Garayed.com  

Go Back   Garayed.com > Linux
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-18-2008, 10:49 PM
Heiner Steven
 
Posts: n/a
Default Re: make cron send an email only when my command goes wrong

Rahul wrote:
> I would like to have cron run a command and then send me an email *only* if
> the command produces some output. I wrote the command to be silent normally
> but it produces output only when things go wrong. When they do go wrong I'd
> like to hear about it. Something like:
>
> 15 * * * * fullpath/my_command.sh 2>&1 | mail -s "strange cron op"
> "me@xxx.xxx"
>
> That's not so good because it always sends me an empty email even when
> things are OK.


One solution would be to save the output to a file, and send its
contents only if it's non-empty:

my_command.sh > /tmp/c$$ 2>&1; [ -s /tmp/c$$ ] && mailx -s "subject" < /tmp/c$$; rm -f /tmp/c$$

Heiner

--
___ _
/ __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de>
\__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 07:48 PM.




LinkBacks Enabled by vBSEO 3.0.0 © 2007, Crawlability, Inc.