The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
script to send mail from unix?? deepaknbk Shell Programming and Scripting 7 08-21-2008 03:03 AM
Script which can send file to diffrent mail ids. vpandey UNIX for Advanced & Expert Users 3 02-29-2008 06:48 AM
script to find a file and send a mail jayaramanit Shell Programming and Scripting 6 09-07-2007 02:41 AM
Script to send a mail in UNIX sudhi Shell Programming and Scripting 1 11-28-2006 03:53 AM
Send e-mail in Shell script annelisa Shell Programming and Scripting 1 07-13-2006 04:35 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-19-2005
Registered User
 

Join Date: Oct 2005
Posts: 1
Stumble this Post!
cron: try script 4 times then send mail and stop

Hi!

I have a simple script i call, and i use CRON to run the script daily between 7 and 8 o'clock. The cron runs 4 times a day between 7 and 8.

The code is simple:

if <script ran successfully>
do something
else
try again later, with the next time cron runs.
BUT If the script failed for the FOURTH time then send mail to admin that this day the script didnt succeed
fi

i am not good at unix or scripting, but ive managed to code everything besides how to gather information that the script has failed four times and its time to send mail. Is this possible by allocating a variable and keeping the state of the variable?

Hopefully there is a easy solution to this problem.

Thanx for your help.

Last edited by bash100; 10-19-2005 at 04:12 AM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-23-2005
Registered User
 

Join Date: Jul 2005
Location: Oak Park, IL
Posts: 97
Stumble this Post!
Cron 4 times in the script if you want email...

...twice via pipe, if the answer is noooo-ooo! (apologies to Tony Orlando and Dawn, and any readers...)

Sure, it's doable:

$CHECKF="/tmp/runcount" # whatever you want
if [ `date | awk '{print $2 $3}'` = `ls -l $CHECKF | awk '{print $6 $7}'` ] ; then # it ran today
if [ `cat $CHECKF` = "0" ] ; then # it ran successfully
exit # so don't run it again.
fi

<run your script>

if <script ran successfully> ; then echo "0" > $CHECKF ; exit; fi

Now here's what happens if you have a problem:

i=`cat $CHECKF`
i=`expr $i + 1`
if expr $i -gt 3` ; then
echo "Script $0 failed 4 times!" | mailx -s "Failure on `date`" recipient
exit 1
fi
echo $i > $CHECKF
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0