Re: a unix script to send email notification when a sas batch job fails?



"Jerry" <greenmt@xxxxxxxxx> writes:

Hi,

This post may be a bit off topic, but essentially it's mainly about
unix script, not SAS (a statistical software). (but I posted it on
comp.soft-sys.sas too hoping for any clue)

My OS is RedHat Enterprise. When I want to run a sas code (say
freq.sas) in background on our server, I simply need to type in command
line "sas freq.sas &".

SAS documentation says that:

"an Exit Status Code can be used to determine the Completion Status of
a SAS Job in UNIX Environments."

and

"The exit status for the completion of a SAS job is returned in $status
for the C shell, and in $? for the Bourne and Korn shells. A value of 0
indicates normal termination."

So I'm wondering if this information could be used to write a short
simple unix script which is able to do the following 2 things:
1, invoke a sas job in batch mode
2, send me an email if this sas batch job fails

Say the name of this unix script is "AutoNotify", and the sas code I
want to run is "freq.sas".

And I hope this script can function this way:
when I type "./AutoNotify freq.sas", it will
1, run freq.sas in background,
2, and will send me an email if the Exit Status Code is not
zero.

Any input is welcome, an sample of such script would be greatly
appreciated. (not a homework question, I just know very little about
unix scripting)

You can learn more about unix scripting. Read: man bash

#!/bin/bash
address="your.self@xxxxxxxxx"
if [ $# = 1 ] ; then
"$1" || printf "Script %s failed with status %s" "$1" "$?" \
| mail -s "notification" "$address"
exit $? # or exit 0
else
printf "Usage:\n AutoNotify program\n"
exit 1
fi


--
__Pascal Bourguignon__ http://www.informatimago.com/
Kitty like plastic.
Confuses for litter box.
Don't leave tarp around.
.



Relevant Pages