Unix Shell - Re: Daily scheduled job, but need to check if previous job has

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > November 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
Janis

2007-11-30, 7:35 am

On 30 Nov., 11:15, 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 . . .


How would the job get restarted in case of a reboot?

Maybe I would let the cronjob create a file with the processing date
and the processing state as his name

current=$( date %Y-%m-%d ).IN_PROGRESS
touch "$current"

which would be renamed just before completed

mv "$current" "${current%.IN_PROGRESS}.DONE"

On startup of the script (after the touch) you could remove existing
DONE files (or make a cleanup manually at times).

Typically I generalize such tasks to let a script catch up processing
since the last successful DONE time stamp for all days until now.

Using the process id $$ is helpful to let processes distinguish their
own environment entities in case that more of these programs can
simultaneously run. (As fas as you specified your task that doesn't
seem to be necessary.)

Janis
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com