|
Home > Archive > Unix Shell > December 2007 > Re: Daily scheduled job, but need to check if previous job has
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Daily scheduled job, but need to check if previous job has
|
|
|
| On Nov 30, 4:15 am, Eliot <e...@hotmail.com> wrote:
> I want to schedule cron to run a script each night, but should there
> have been a lot of activity during the day, the script may take more
> than a day to complete. So I need to check if the previous days job
> has finished before starting today's. It doesn't matter if the script
> doesn't run on the odd night here and there - I know that on average
> the system will manage to keep up.
>
> A friend has suggested to use a "touch" file but what if the system
> crashes or some one reboots it - the touch file will still be present
> and prevent the script from being run again. The friend also
> suggested using a the process id for the script, but I am unsure how
> to do this . . .
Could you just run a ps and see the process is running? If it's in
cron I'm assuming it the same script each night. I use something like
this to make sure the same script doesn't run twice against an oracle
server:
PROGRAM_NAME=$0
########################################
########################################
###
# Is this job already running?
########################################
########################################
###
if [[ $(ps -ef | egrep -v "run_job|timeout|grep|$$" | grep
"$PROGRAM_NAME" | grep -c $INSTANCE) -gt 0 ]]
then
print_status_message "\nERROR: it looks like $PROGRAM_NAME is
already running against $INSTANCE." ERROR
RETCODE=102
error_exit
fi
|
|
|
|
|