Unix Programming - a unix script to send email notification when a sas batch job fails?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > March 2006 > a unix script to send email notification when a sas batch job fails?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author a unix script to send email notification when a sas batch job fails?
Jerry

2006-03-15, 8:48 pm

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)

Thank you very much in advance !!!

Pascal Bourguignon

2006-03-15, 8:48 pm

"Jerry" <greenmt@gmail.com> 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@your.host"
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.
Roger Leigh

2006-03-15, 8:48 pm

"Jerry" <greenmt@gmail.com> writes:

> 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


sas || echo 'SAS failed' | mail -s 'SAS FAIL' 'me@somewhere' &

--
Roger Leigh
Printing on GNU/Linux? http://gutenprint.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
Bit Twister

2006-03-15, 8:48 pm

On 15 Mar 2006 16:20:17 -0800, Jerry wrote:
>
> 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)


These might help

! bash script introduction documentation
http://tldp.org/LDP/intro-linux/html/index.html

! bash script advanced documentation
http://tldp.org/LDP/abs/html/index.html
William Park

2006-03-17, 8:53 pm

Jerry <greenmt@gmail.com> wrote:
> 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)
>
> Thank you very much in advance !!!


Solution:
sas freq.sas || mail -s "SAS job failed" your@address < /dev/null

Wait... I gave away solution for free... doh!

--
William Park <opengeometry@yahoo.ca>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com