![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages 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 06:03 AM |
| Script which can send file to diffrent mail ids. | vpandey | UNIX for Advanced & Expert Users | 3 | 02-29-2008 10:48 AM |
| script to find a file and send a mail | jayaramanit | Shell Programming and Scripting | 6 | 09-07-2007 05:41 AM |
| Script to send a mail in UNIX | sudhi | Shell Programming and Scripting | 1 | 11-28-2006 07:53 AM |
| Send e-mail in Shell script | annelisa | Shell Programming and Scripting | 1 | 07-13-2006 07:35 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 07:12 AM.. |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|