1753847 Members
8481 Online
108807 Solutions
New Discussion юеВ

Re: Automating

 
SOLVED
Go to solution
Adam W.
Valued Contributor

Automating

Guru's last question today I promise.

I am running a command line virus scanner. So I set a cronjob to run it every sunday at 4:30 PM and send the output to a file in my homdir as below:

#30 16 * * 0 /usr/local/bin/uvscan/uvscan >> /home/name/scanresults

My question is how would I have these scan results automatically sent to my outlook e-mail address? Would I just put it is the crontab after the >> /home/name/scanresults? something like :

mail -s 'Subject' somewhere@domain.com < /home/name/scanresults


or is there an easier/better way?
There are two types of people in the world, Marines and those who wish they were.
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: Automating

Hi:

Any output (STDOUT or STDERR) that is not redirected (to a file) when executed in a 'cron'd task is sent to the user as mail.

Hence, you could setup a '.forward' file in your ${HOME} directory that contains the line:

somewhere@domain.com

The '.forward' should be owned by the user and readable only by the same.

Otherwise, the 'mail' syntax you showed would also work.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Automating

Hi (again) Adam:

By the way, as a 'sendmail' requirement you must (of course) have the 'DJ' macro ("smart relay") defined in your '/etc/mail/sendmail.cf' something like:

DSexchange.domain.com

Regards!

...JRF...
Adam W.
Valued Contributor

Re: Automating

James,
Unfortunately, we cannot have .forward file on our systems (Government regulation) we are allowed .alias files though. I could, in theory set it up the same yes?
There are two types of people in the world, Marines and those who wish they were.
Adam W.
Valued Contributor

Re: Automating

but I digress. James, just to confirm if I did :

#30 16 * * 0 /usr/local/bin/uvscan/uvscan >> /home/name/scanresults mail -s 'scanresults' me@mine.com

would it work?
There are two types of people in the world, Marines and those who wish they were.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Automating

Hi (again) Adam:

> we are allowed .alias files though. I could, in theory set it up the same yes?

Yes, see the '/etc/mail/aliases' file. You might just as well 'cron' something like:

# 30 16 * * 0 /usr/local/bin/uvscan/uvscan|mailx -s "The Subject" somewhere@domain.com

...eliminating the temporary file.

Regards!

...JRF...
Adam W.
Valued Contributor

Re: Automating

ah, ya know what I didn't even think about it. For some reason I was thinking I HAD to send it to a file first. But then again, that is why your a guru and I am not. James, thank you (yet again) with all of your help.
There are two types of people in the world, Marines and those who wish they were.
Adam W.
Valued Contributor

Re: Automating

James, once again always a pleasure. Thanks for the help.
There are two types of people in the world, Marines and those who wish they were.
Dennis Handly
Acclaimed Contributor

Re: Automating

>JRF: /usr/local/bin/uvscan/uvscan | mailx -s "The Subject" ...

If you want to also send stderr you would need to do:
/usr/local/bin/uvscan/uvscan 2>&1 | mailx -s "The Subject" ...