Thursday, February 25, 2016

cron - anacron screws my crontab?



My system is CentOS 6.3 , I notice my /etc/cron.daily are not executed at 4:01 AM , instead , these scripts are executed at random time . I searched and seemed it is 'anacron' that screws up my crontab. For example , these is part of my log file from /var/log/cron :



Oct  1 04:01:01 xfiles anacron[7350]: Anacron started on 2012-10-01
Oct 1 04:01:01 xfiles anacron[7350]: Will run job `cron.daily' in 18 min.
Oct 1 04:01:01 xfiles anacron[7350]: Jobs will be executed sequentially
Oct 1 04:01:01 xfiles run-parts(/etc/cron.hourly)[7352]: finished 0anacron

Oct 1 04:19:01 xfiles anacron[7350]: Job `cron.daily' started

Oct 2 03:01:01 xfiles anacron[8810]: Anacron started on 2012-10-02
Oct 2 03:01:01 xfiles anacron[8810]: Will run job `cron.daily' in 36 min.
Oct 2 03:01:01 xfiles anacron[8810]: Jobs will be executed sequentially
Oct 2 03:01:01 xfiles run-parts(/etc/cron.hourly)[8812]: finished 0anacron
Oct 2 03:37:01 xfiles run-parts(/etc/cron.daily)[10133]: starting 00webalizer

Oct 3 03:01:01 xfiles anacron[14989]: Will run job `cron.daily' in 30 min.
Oct 3 03:01:01 xfiles anacron[14989]: Jobs will be executed sequentially

Oct 3 03:01:01 xfiles run-parts(/etc/cron.hourly)[14991]: finished 0anacron
Oct 3 03:31:01 xfiles anacron[14989]: Job `cron.daily' started
Oct 3 03:31:01 xfiles run-parts(/etc/cron.daily)[16301]: starting 00webalizer

Oct 4 03:01:01 xfiles anacron[16357]: Will run job `cron.daily' in 12 min.
Oct 4 03:01:01 xfiles anacron[16357]: Jobs will be executed sequentially
Oct 4 03:01:01 xfiles run-parts(/etc/cron.hourly)[16359]: finished 0anacron
Oct 4 03:13:01 xfiles anacron[16357]: Job `cron.daily' started
Oct 4 03:13:01 xfiles run-parts(/etc/cron.daily)[16692]: starting 00webalizer


Oct 5 03:01:01 xfiles anacron[19413]: Will run job `cron.daily' in 29 min.
Oct 5 03:01:01 xfiles anacron[19413]: Jobs will be executed sequentially
Oct 5 03:01:01 xfiles run-parts(/etc/cron.hourly)[19415]: finished 0anacron
Oct 5 03:30:01 xfiles anacron[19413]: Job `cron.daily' started
Oct 5 03:30:01 xfiles run-parts(/etc/cron.daily)[20086]: starting 00webalizer


You can see that the /etc/cron.daily just cannot start at a fixed time. Sometimes at 3:30 , sometimes at 3:13 , and sometimes at 3:37 , or 4:19 ...



In previous CentOS (5.x) , /etc/cron.daily starts at 4:01 AM correctly. But I just cannot figure how CentOS6's anacron screws up the cron schedule . How to make the system just behave as CentOS 5.x , that starts /etc/cron.daily just at a fixed time (4:01 , for example) ?




Thanks.



(This is a 24/7 server , no shut-down problem )


Answer



If RANDOM_DELAY is set in your /etc/anacrontab, it's the expected behaviour.



Verbatim copy from the manualpage anacrontab(5):





If the RANDOM_DELAY environment variable is set, then a random value
between 0 and RANDOM_DELAY minutes will be added to the start up delay
of the jobs. For example a RANDOM_DELAY set to 12 would therefore add,
randomly, between 0 and 12 minutes to the user defined delay.




This might explain your symptoms.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...