Results 1 to 5 of 5
Hi ,I am running a script from crontab and would like a crontab to mail me only if there is an error.
Here is what I have in crontab:
Code:
...
- 06-18-2010 #1
crontab stderr only
Hi ,I am running a script from crontab and would like a crontab to mail me only if there is an error.
Here is what I have in crontab:
The trouble is that I still seem to get mailed part of the successful output even with > /dev/null in place.Code:MAILTO="myemailaddress" 0 1 * * * /home/admin/scripts/backup.sh >/dev/null
Without > /dev/null:
With > /dev/null:Code:Stopping slapd: [ OK ] Checking configuration files for slapd: config file testing succeeded [ OK ] Starting slapd: [ OK ]
Be great if someone could shed some light on this for me.Code:config file testing succeeded
Thanks
- 06-18-2010 #2Just Joined!
- Join Date
- Mar 2006
- Location
- Manila, Philippines
- Posts
- 3
RE: crontab stderr only
Hi feisar, you can try using 2> whi'ch redirects error output instead of using >. which redirect standard output. But it seems that by changing > to 2> the logic of the script will also change.
- 06-19-2010 #3Just Joined!
- Join Date
- Jul 2008
- Posts
- 81
Your script "backup.sh" seems to be producing output to stderr whether or not it is successful. Like the message "config file testing succeeded".
Cron can't tell the difference between a success and a failure message since they are both being sent to stderr. The message output is mailed to you. If you don't want this, change the output of "backup.sh" to say nothing if it succeeds. This is the Unix way of doing things.
- 06-19-2010 #4Just Joined!
- Join Date
- Mar 2010
- Posts
- 1
RE: crontab stderr only
clowenstein is correct. Your script is putting out to stderr a non error message "config file testing succeeded". You need to fix this before the logic you want to use will work.
- 06-19-2010 #5Just Joined!
- Join Date
- Jun 2007
- Posts
- 16
maybe something like::::
#!/bin/bash
service start <something> > /tmp/somefile 2>&1
if [ $? != 0 ]
then
mail -s "<some kind of subject" somebody@<somedomain> < /tmp/somefile
fi
exit


Reply With Quote