Ubuntu – Are multiple @daily crontab entries processed in order, serially

cronlinuxUbuntu

I want two jobs to run sometime every day, serially, in exactly the order I specify. Will this crontab reliably do what I want?

@daily job1
@daily job2

I'm assuming they run one after the other, but I was unable to find the answer by searching the Web or from any of these manpages: cron(1), crontab(1), crontab(5).

The crontab above obviously won't do what I want if cron runs things scheduled with @daily in parallel or in an unpredictable order.

I know I can simply make one shell script to fire them off in order, I'm just curious how cron is supposed to work (and I'm too lazy to gather test data or read the source code).

Cron is provided by the cron package. OS is Ubuntu 10.04 LTS (server).

Best Answer

After a quick glance at the source (in Debian squeeze, which I think is the same version), it does look like entries within a given file and with the same times are executed in order. For this purpose, @daily and 0 0 * * * are identical (in fact @daily is identical to 0 0 * * * in this cron).

I would not rely on this across the board. It's possible that one day someone will decide that cron should run jobs in parallel, to take advantage of these 32-core CPUs that have 31 cores running idle. This might be done when implementing this 20-year old todo item encountered in the cron source:

All of these should be flagged and load-limited; i.e., instead of @hourly meaning "0 * * * *" it should mean "close to the front of every hour but not 'til the system load is low". (…) (vix, jan90)

It's very easy to write @daily job1; job2 here. If it's important that the jobs execute in order, make it a direct consequence of what you write.

Additionally, making the order explicit removes the risk that a future administrator will reorder the lines thinking that it won't matter.

Related Question