cron: try script 4 times then send mail and stop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cron: try script 4 times then send mail and stop
# 1  
Old 10-19-2005
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 08:12 AM..
# 2  
Old 10-23-2005
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Client was not authenticated to send anonymous mail during MAIL FROM (in reply to MAIL FROM comm

I am having trouble getting mail to work on a red hat server. At first I was getting this message. Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to :25: Connection refused Then added the port to my firewall. Then I temporarily turned off selinux. I then copied this file... (1 Reply)
Discussion started by: cokedude
1 Replies

2. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

Script that will send an email if the cron job did not run.

Team, Would like to know what is the best script that will send you an email if cronjob did not run. Thanks (4 Replies)
Discussion started by: kenshinhimura
4 Replies

4. Shell Programming and Scripting

To send a mail through shell script

I want to send a mail through shell script,If it is possible Please give me a code. mail id : upload.xxx@example.com (8 Replies)
Discussion started by: kannansoft1985
8 Replies

5. Shell Programming and Scripting

Script runs in command-line fine but times out in CRON?

Hi, I have a script that seems to run to completion when in the command-line, but when it is run using the cron, it seems to time out. They both start and run fine, but on the CRON it stops prematurely. The script hits an API every few seconds and grabs data. Does anyone have any idea on... (4 Replies)
Discussion started by: phpchick
4 Replies

6. Shell Programming and Scripting

script to send mail !!

Hi Experts.. i have created a table with the fields, empid name mailid 1 raja raja@xy.com and entered the values of all persons who are in that file... i have a .csv file date shift1 shift2 6/6/2011 ram raja Now i want a script that could fetch the data in (input file .csv file) and... (3 Replies)
Discussion started by: cratercrabs
3 Replies

7. Shell Programming and Scripting

how to run a script using cron job and send the output as attachment via e-mail using unix

how to run a script using cron job and send the output as attachment via e-mail using unix. please help me. how my cron job entry should be? As of now my cron job entry is to run the script at specific time, 15 03 * * * /path/sample.sh | mail -s "Logs" email_id In the above entry, what... (8 Replies)
Discussion started by: vidhyaS
8 Replies

8. Shell Programming and Scripting

Help-send mail script

Hi, I have written one script for sending mails with attachment. currently its working for only one recipient. I want to send mails to n number of users by taking user input i.e number of users. Output of current script: Enter how many files : 1 Enter First Name : kiran E-Mail... (2 Replies)
Discussion started by: kiran_j
2 Replies

9. UNIX for Advanced & Expert Users

need to configure mail setting to send mail to outlook mail server

i have sun machines having solaris 9 & 10 OS . Now i need to send mail from the machines to my outlook account . I have the ip adress of OUTLOOK mail server. Now what are the setting i need to do in solaris machines so that i can use mailx or sendmail. actually i am trying to automate the high... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

10. Shell Programming and Scripting

Grep Stop status from the output of script and send an eamil alert.

Hello Team, I have script which gives below output. Server clustServer11 is in a STARTED state Server clustServer12 is in a STOPPED state Server clustServer21 is in a STOPPED state I would like to prepare script which will grep stop word from the above output and send an email alert. (5 Replies)
Discussion started by: coolguyamy
5 Replies
Login or Register to Ask a Question