I want to add a line to the script that searches for a file. If the file does not exist, I need to kill the cronjob and run it again in one hour. I am running the program and 2 am and 2pm. I would want the job to run again at 3am and 3pm respectively. How could I do this and still keep the cronjob running twice daily if I killed it once? The cronjob simply runs one file. example
. Then filebatch.sh runs several other files, example
. Filebatch2.sh is a script that uses wget to pull files that I need to run the program. If the files are not ready, I want it to kill the entire job and run it again in 1 hour. I would like to put the line of code right after the command
. How would I do this. I think I am using a linux machine with a c shell. See below.
---------- Post updated at 01:18 PM ---------- Previous update was at 12:09 PM ----------
Looks like I also have bash installed on the box. It looks like when I use an sh command it runs bash
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):
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:
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)
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)
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)
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)
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)
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)
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)