Sponsored Content
Top Forums Shell Programming and Scripting Rerun a cronjob if it doesn't work at first. Post 302444433 by agama on Wednesday 11th of August 2010 11:38:19 PM
Old 08-12-2010
Cron is a very basic scheduler without any real conveniences such as retries, so you'll need to get creative.

My first thought is to schedule the script at both times (2pm and 3pm for instance) and have the first script delete, or move, the input file. The second execution will fail because the first execution processed the file, and if the file wasn't there for the first execution, the second should find it. If the script is already deleting/moving the file, then no changes will be needed.

If you need to keep the file, another simple solution would be to have the script sleep for an hour and retry if it doesn't find the file initially. Depending on the complexity of your script this will require the least amount of change to your script.

The only other way that I can think of is a bit of a kludge, and will require a few modifications to your script, but it will work.

First, modify your script to create a 'rerun' file in /tmp or some other known location when it is not able to find the file that it needs. It then exits.

A second modification, to accept a check option from the command line is also necessary. If the check option is present, then the script should initially test for the 'rerun' file. If the rerun file isn't present, then the script should immediately exit. The fact that there is no rerun file indicates that the earlier execution was successful.

Once those changes are made, add two more lines to your crontab that invoke the script at 3pm and 3am with the check option.

A small (untested) example of this (ksh/bash Im not a Csh person at all):
Code:
#!/usr/bin/env ksh

create_rerun=1            # default to creating rerun on failure
if [[ $1 == -c ]]
then
   if [[ ! -f /tmp/my.rerun ]]
   then
       echo "did not find rerun file; exiting OK"
       exit 0
    fi

   create_rerun=0     # don't create a rerun on failure 
fi

rm -f /tmp/my.rerun            # ensure that the rerun file is gone
if [[ ! -f needed_file_name ]]
then
   echo "unable to find needed file"
   if (( $create_rerun > 0 ))
   then
      touch /tmp/my.rerun
      exit 0                       # stop now, an ok return code
   fi
   exit 1                 # stop now -- error
fi

# what ever code you have to manipulate the file

If the script cannot be modified, then create a small 'wrapper' that is basically the code above and invoke the wrapper from cron. The wrapper then invokes the real script, but only if the file exists.

The crontab entries would be something like this for the check method:

Code:
0 2 * * * /usr/home/me/bin/myscript 
0 3 * * * /usr/home/me/bin/myscript -c

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cronjob process not work

Hi all, I having a very unknown problem. I set my process to cronjob but it does not work at all!!!!!!No error detected, just nothing.... Cron: 15 * * * * /process/directory/path/$processname.sh Script($processname.sh): nohup $process & Please help. I have no idea at all.... (3 Replies)
Discussion started by: clemeot
3 Replies

2. UNIX for Dummies Questions & Answers

Repquota doesn't work as Cronjob?!?

Hello: I'm trying to run repquota -ag > /home/usersdir/repquota.txt as a daily cronjob at midnight, but the file always ends up blank. I even tried writing a quick Perl script to e-mail me what running that command outputs, and it's nothing. Can root run repquota as a cronjob? Do I have... (1 Reply)
Discussion started by: b416
1 Replies

3. Shell Programming and Scripting

Why doesn't this work?

cat .servers | while read LINE; do ssh jason@$LINE $1 done exit 1 ./command.ksh "ls -l ~jason" Why does this ONLY iterate on the first server in the list? It's not doing the command on all the servers in the list, what am I missing? Thanks! JP (2 Replies)
Discussion started by: jpeery
2 Replies

4. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

5. UNIX for Dummies Questions & Answers

how can i know that cronjob work status

how can i know that cronjob work status(like completed or throws any error) (2 Replies)
Discussion started by: ss4u
2 Replies

6. UNIX for Dummies Questions & Answers

FTP doesn't work

Hi! I have 2 servers. The firts has vsftpd server with this configuration: # Example config file /etc/vsftpd.conf # # The default compiled in settings are fairly paranoid. This sample file # loosens things up a bit, to make the ftp daemon more usable. # Please see vsftpd.conf.5 for all... (2 Replies)
Discussion started by: Torquemada
2 Replies

7. Shell Programming and Scripting

Doesn't run as a cronjob...

Hi! I have a svn backup script that works perfectly if I execute it from the command line but if I set it as a cronjob to run at night, only part of the code works. So, basically the scripts starts by deleting the folder yesterday and then moves the folder today to the folder yesterday. When... (4 Replies)
Discussion started by: ruben.rodrigues
4 Replies

8. UNIX for Dummies Questions & Answers

Why doesn't this work?

find . -name "05_scripts" -type d -exec mv -f {}/'*.aep\ Logs' {}/.LogFiles \; Returns this failure: mv: rename ./019_0120_WS_WH_gate_insideTEST/05_scripts/*.aep\ Logs to ./019_0120_WS_WH_gate_insideTEST/05_scripts/.LogFiles/*.aep\ Logs: No such file or directory I don't know why it's trying... (4 Replies)
Discussion started by: scribling
4 Replies

9. Shell Programming and Scripting

-ne 0 doesn't work -le does

Hi, I am using korn shell. until ] do echo "\$# = " $# echo "$1" shift done To the above script, I passed 2 parameters and the program control doesn't enter inside "until" loop. If I change it to until ] then it does work. Why numeric comparison is not working with -ne and works... (3 Replies)
Discussion started by: ab_2010
3 Replies
Logcheck(8)						      System Manager's Manual						       Logcheck(8)

NAME
logcheck -- program to scan system logs for interesting lines SYNOPSIS
logcheck [OPTIONS] DESCRIPTION
The logcheck program helps spot problems and security violations in your logfiles automatically and will send the results to you periodi- cally in an e-mail. By default logcheck runs as an hourly cronjob just off the hour and after every reboot. logcheck supports three level of filtering: "paranoid" is for high-security machines running as few services as possible. Don't use it if you can't handle its verbose messages. "server" is the default and contains rules for many different daemons. "workstation" is for shel- tered machines and filters most of the messages. The ignore rules work in additive manner. "paranoid" rules are also included at level "server". "workstation" level includes both "paranoid" and "server" rules. The messages reported are sorted into three layers, system events, security events and attack alerts. The verbosity of system events is controlled by which level you choose, paranoid, server or workstation. However, security events and attack alerts are not affected by this. EXAMPLES
logcheck can be invoked directly thanks to su(8) or sudo(8), which change the user ID. The following example checks the logfiles without updating the offset and outputs everything to STDOUT. sudo -u logcheck logcheck -o -t OPTIONS
A summary of options is included below. -c CFG Overrule default configuration file. -d Debug mode. -h Show usage information. -H Use this hostname string in the subject of logcheck mail. -l LOG Run logfile through logcheck. -L CFG Overrule default logfiles list. -m Mail report to recipient. -o STDOUT mode, not sending mail. -p Set the report level to "paranoid". -r DIR Overrule default rules directory. -R Adds "Reboot:" to the email subject line. -s Set the report level to "server". -S DIR Overrule default state directory. -t Testing mode does not update offset. -T Do not remove the TMPDIR. -u Enable syslog-summary. -v Print current version. -w Set the report level to "workstation". FILES
/etc/logcheck/logcheck.conf is the main configuration file. /etc/logcheck/logcheck.logfiles is the list of files to monitor. /usr/share/doc/logcheck-database/README.logcheck-database.gz for hints on how to write, test and maintain rules. EXIT STATUS
0 upon success; 1 upon failure SEE ALSO
logtail(8) AUTHOR
logcheck is developed by Debian logcheck Team at alioth: http://alioth.debian.org/projects/logcheck/. This manual page was written by Jon Middleton. Logcheck(8)
All times are GMT -4. The time now is 07:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy