Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Dec 2019 11:38:39 -0800
From:      "Jin Guojun[VFF]" <jguojun@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Program order in crontab
Message-ID:  <9bd9c6a3-0690-4b2b-e8d3-1cadf32236d8@gmail.com>
In-Reply-To: <20191230143159.GA80921@thismonkey.com>
References:  <mailman.102.1577707201.34855.freebsd-questions@freebsd.org> <20191230143159.GA80921@thismonkey.com>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
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




Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?9bd9c6a3-0690-4b2b-e8d3-1cadf32236d8>