Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to send mail to user if a script fails? nt

Status
Not open for further replies.

Madz

Technical User
Jan 31, 2001
33
SE
How to send mail to user if a script fails? nt

thanks in advance!
/mats
 
#/usr/bin/ksh

myscript.sh
success=$?
if [ $success -eq 0 ]; then
echo "script successfull"
else
echo "Script failed!!!" | mail -s "Myscript" \ me@somehwere.com
fi

NOTE: myscript.sh must explicitly return a value eg. "return 0" for success or anything else for failure.
Scripts that finish without a return statement return whatever the last statement returns. If you use return within a function, it will just exit the function. (In contrast, the statement exit N exits the entire script, no matter how deeply you are nested in functions.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top