The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-19-2005
bash100 bash100 is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 1
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..
  #2 (permalink)  
Old 10-23-2005
mschwage mschwage is offline
Registered User
  
 

Join Date: Jul 2005
Location: Oak Park, IL
Posts: 102
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0