Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 ?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
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. –  Nikolay Jan 6 at 0:01

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.