a unix script to send email notification when a sas batch job fails?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > a unix script to send email notification when a sas batch job fails?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 01:48 AM

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 !!!






[ Post a follow-up to this message ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 01:48 AM

"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.





[ Post a follow-up to this message ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 01:48 AM

"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.





[ Post a follow-up to this message ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 01:48 AM

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





[ Post a follow-up to this message ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-18-06 01:53 AM

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/





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:15 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register