[PLUG] handling error in shell script

Derek Loree derek at infotects.com
Fri Jan 24 14:16:02 UTC 2003


Hi All,

I have shell script that runs as a cron job, all it does is remove a
file, then copy a new file to that location.  This works, except that I
have no way of knowing if it fails (without rooting through the log
files).  I can also create a script that will email a message to me. 
What I would like to do is have the cron job send me an email if the
copy command fails.  What I tried was to modify my ping-the-servers
script, which has lines in it like this (this is just one line):

ping -c 3 www.infotects.com >> ${LOGFILE} || echo "The web server is
down, fix it now!" | mail -s "Web server is down" derek at infotects.com

This sends me an email only if the ping command fails (that is what the
double pipe does, it is a command level OR).  But in my copy script, I
have (again just one line):

cp -Rp /home/test/* /home/test2 || echo "copy failed, better fix it" |
mail -s "Copy Failed" derek at infotects.com

Which sends me an email even when the copy is successful!

I sure could use some ideas about how to make this work.

Thanks,

Derek Loree





More information about the PLUG mailing list