Program order in crontab
Jin Guojun[VFF]
jguojun at gmail.com
Mon Dec 30 19:38:49 UTC 2019
On 12/30/19 06:31, Scott wrote:
>> In a standard 'crontab', if I have three programs as show below, do they
>> run in order as listed or all at one time, or something else? Does each
>> program finish before the next one starts?
>>
>> */5 * * * * /usr/home/gerard/Scripts/Program1.sh
>> */5 * * * * /usr/home/gerard/Scripts/Program2.sh
>> */5 * * * * /usr/home/gerard/Scripts/Program3.sh
>>
>> Thanks
>>
>> --
>> Jerry
> They would run asynchronously, although I'm not sure of the order they would
> be started.
>
> The cron code may shed some light (I would assume top down but I haven't
> checked the code).
>
> If you wanted to ensure they are run synchronously just put them on one line
> separated with a '; '.
The order of job execution in cron is typically bottom-up in FreeBSD or
top-down in Linux.
Additional, all jobs are executed in parallel if they have the same time
scheduled, and cron has no guarantee for which one can be executed and
completed in any order.
This may be an ancient topic that above cronjob is not desired. If P1,
P2, P3... order is expected, people should do following:
*/5 * * * * /usr/home/gerard/Scripts/Batch.sh
Including P1, .. Pn commands in /usr/home/gerard/Scripts/Batch.sh file as:
BPATH=$(cd `dirname $0`; pwd) # if all commands in the same dir; or set BPATH to where other commands are
$BPATH/P1.sh
$BPATH/P2.sh
$BPATH/P3.sh
...
$BPATH/Pn.sh
This also makes easier to change the job and/or the order without mucking the crontab.
-Jin
More information about the freebsd-questions
mailing list