5

This page http://wiki.ci.uchicago.edu/I2U2/WebalizerConfiguration suggests renaming /etc/cron.daily/logrotate so it comes after /etc/cron.daily/webalizer - webalizer should be done before logrotate kicks in.

Is that true ? Will cron.daily wait for jobs to finish before starting the next one ?

2 Answers 2

6

The scripts in cron.daily and the others are executed using run-parts if anacron is not installed. You can see this in /etc/crontab:

25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

run-parts will execute each executable in the directory, and wait for each to complete before running the next. Here is a test using these two scripts:

$ cat cron/1test
#!/bin/bash
date
echo script1
sleep 10
date


$ cat cron/2test
#!/bin/bash
date
echo script2
sleep 10
date

Output:

$ run-parts --verbose cron
run-parts: executing cron/1test
Monday 6 January  10:38:42 EST 2014
script1
Monday 6 January  10:38:52 EST 2014
run-parts: executing cron/2test
Monday 6 January  10:38:52 EST 2014
script2
Monday 6 January  10:39:02 EST 2014

This differs from scheduling each job in cron, which will run them parallel if they overlap.

1
  • Good job on finding this. After I posted my answer I got an idea cron executes them in different way (/etc/crontab and cron.daily stuff). Well done.
    – VL-80
    Jan 6, 2014 at 0:01
1

I just created test cron job which executes every minute:

#!/bin/bash

echo "123" >> /home/user/test-file

sleep 100

echo "234" >> /home/user/test-file

So I did see overlap in htop. I mean there was periods of time when I saw two processes running simultaneously. 123 was echoed at the begging of the minute and 234 was echoed at 40 seconds of next minute (because of sleep 100). In period of 40 seconds to beginning of next minute there was just one process.

That means cron fires jobs and does not wait for them to finish.

I'll try to represent it graphically:

0 minute 00 seconds 123 <----first execution
1 minute 00 seconds 123 <----second execution
1 minute 40 seconds 234 <----first execution
2 minute 00 seconds 123 <----third execution
2 minute 40 seconds 234 <----second execution
3 minute 00 seconds 123 <----fourth execution
3 minute 40 seconds 234 <----third execution

At least this is true for jobs in the /etc/crontab with vixie-cron on fresh updated Gentoo.

As Paul discovered - stuff in cron.daily executes in the different way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .