Re: graceful script exit

From: Bob.Kelley@BRINKSINC.COM
Date: Fri Apr 23 2004 - 13:55:01 EDT


Thanks!

Bobby Kelley Jr.
972-877-5341

|---------+---------------------------->
| | "Taylor, David" |
| | <DTaylor@WBMI.COM|
| | > |
| | Sent by: IBM AIX |
| | Discussion List |
| | <aix-l@Princeton.|
| | EDU> |
| | |
| | |
| | 04/23/2004 11:24 |
| | AM |
| | Please respond to|
| | IBM AIX |
| | Discussion List |
| | |
|---------+---------------------------->
>---------------------------------------------------------------------------------------------------------------------------------------------|
  | |
  | To: aix-l@Princeton.EDU |
  | cc: |
  | Subject: Re: graceful script exit |
>---------------------------------------------------------------------------------------------------------------------------------------------|

Check the exit codes of each command as they complete. Then set the
exit code of your script to something that you can translate back to the
failed command:

i.e.

-----------
integer RETURN=0

tar -cf /tarballs/mytar.tar /stuff/to/tar
if [ $? -ne 0 ]; then
  RETURN=123 # I will know that an exit of 123 means a problem with the
tar
fi

<other commands>

if [ $RETURN -ne 0 ]; then
   echo "error message" | mail -s "problems" me@foobar.com
fi

exit $RETURN
-----------

The only problem with this method is that if more than one command
fails, it will only report that last one. You code do something with
adding the return codes together (i.e. command #1 = 0 or 1, command #2 =
00 or 10) I don't know (off hand) what the limitation is for the
ceiling on exit codes.

HTH

David Taylor
Senior Software Systems Engineer
West Bend Mutual Insurance
(262) 335-7077

-----Original Message-----
From: IBM AIX Discussion List [mailto:aix-l@Princeton.EDU] On Behalf Of
Bob.Kelley@BRINKSINC.COM
Sent: Friday, April 23, 2004 11:02 AM
To: aix-l@Princeton.EDU
Subject: graceful script exit

If I have a script with does a number of things like tars, copy
commands,
etc. What is the best way to generate a flag if a SINGLE command in the
script fails? In other words, if I'm thinking about this correctly, I
want
to get a page when the script is finished, and one command didn't finish
correctly, even if some of the commands have succeeded. Thanks!

Bobby Kelley Jr.
972-877-5341

**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************

NOTICE TO BRINK'S EMPLOYEES:
All electronic mail communications composed, sent, received or stored on or
through Brink's equipment are subject to the Brink's Electronic
Communications Policy. Employees should have no expectation of privacy in
their use of the Company's electronic mail system.



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:17:51 EDT