Date: Mon, 20 Mar 2006 08:02:00 -0800
Reply-To: Jerry <greenmt@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jerry <greenmt@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: a unix script to send email notification when a sas batch job
fails?
In-Reply-To: <47t7okFhgud2U1@individual.net>
Content-Type: text/plain; charset="iso-8859-1"
Hi ,
I just wanted to update this thread with what I found. It turns out a
script is not needed to archieve what I want.
The modified solution (originally contributed by Roger Leigh @
comp.unix.programmer) is:
sas freq.sas || echo "exit code $?" | mail -s "this sas code failed"
me@somewhere &
The tricky part (to me) is the use of "||", see below for more.
Richard, I definited agree with you that what I wanted is not robust at
all. But it's much better than frequently runing "jobs" to see if it
dies, or search logs for "ERRORS" or "WARNINGS" next morning.
You mentioned that "(using one of the log parsers {found mentioned in
several conference papers})". I used "log parser" as keyword to search
SUGI papers, but didn't find anything useful. Could you please point me
to such "conference papers"? Thank you!.
Thanks Logan Shaw @ comp.unix.programmer, he has a clear and detailed
explanation about the use of the "||" conditional shell operator.
Below is what I quoted from his post:
*********************
Briefly, the "||" operator is a lazy "or", so it will only run the
second command if the first fails. Since "true" is a command that
always succeeds (well, always tries to succeed...) and "false" is
a command that always fails, you can easily try this out on the
command line. Try the following two commands:
true || date
false || date
You should see that the first one doesn't print the date and the
second one does. That's because "true" succeeds; therefore, "date"
isn't run. And the opposite happens with "false". You can use a
similar construct to get a notification if your command fails:
sas freq.sas || date
That would print the date if the "sas" command fails.
****************************