FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 03-05-2009, 12:46 AM
Matthew Flaschen
 
Default How to get cron job to mail output only if non-empty

David Karr wrote:
> I have a (root) cron job definition like the following:
>
> 0 0 * * * /usr/bin/clamscan --no-summary -r --reload
> --log=/var/log/clamav/clamscan.log -i / | mail -s "Virus scan found
> something" davidmichaelkarr@gmail.com
>
> This works fine when it finds something (I tested it with a fake virus
> file), but what I didn't expect is that "mail" sends the mail even if the
> output is empty.

You're trying to reinvent the wheel. Read man cron:

"When executing commands, any output is mailed to the owner of the
crontab (or to the user named in the MAILTO environment variable in the
crontab, if such exists)."

Drop the mail -s "Virus scan found something" davidmichaelkarr@gmail.com
and use MAILTO instead. cron will only send emails there when there is
actual output.

See also http://usertools.plus.net/tutorials/id/1

Matt Flaschen

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-06-2009, 02:05 PM
David Karr
 
Default How to get cron job to mail output only if non-empty

On Wed, Mar 4, 2009 at 5:46 PM, Matthew Flaschen <matthew.flaschen@gatech.edu> wrote:

David Karr wrote:

> I have a (root) cron job definition like the following:

>

> 0 0 * * * /usr/bin/clamscan --no-summary -r --reload

> --log=/var/log/clamav/clamscan.log -i / | mail -s "Virus scan found

> something" davidmichaelkarr@gmail.com

>

> This works fine when it finds something (I tested it with a fake virus

> file), but what I didn't expect is that "mail" sends the mail even if the

> output is empty.



You're trying to reinvent the wheel. *Read man cron:



"When *executing *commands, any output is mailed to the owner of the

crontab (or to the user named in the MAILTO environment variable in the

crontab, if such exists)."



Drop the mail -s "Virus scan found something" davidmichaelkarr@gmail.com

and use MAILTO instead. *cron will only send emails there when there is

actual output.



See also http://usertools.plus.net/tutorials/id/1




Thanks, that worked fine.

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 12:43 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org