Is one meant to have one or the other? If so, which is recommended? I have -------------------------------- [tim@helen etc]$ cat anacrontab # /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root
1 65 cron.daily run-parts /etc/cron.daily 7 70 cron.weekly run-parts /etc/cron.weekly 30 75 cron.monthly run-parts /etc/cron.monthly -------------------------------- [tim@helen etc]$ cat crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/
# run-parts 01 * * * * root run-parts /etc/cron.hourly 02 4 * * * root run-parts /etc/cron.daily 22 4 * * 0 root run-parts /etc/cron.weekly 42 4 1 * * root run-parts /etc/cron.monthly -------------------------------- I didn't write either of these, they must have been automatically installed.
My impression is that anacrontab was ignored until recently, but now as far as I can see both are being read and acted on.
Any enlightenment gratefully received.
Is one meant to have one or the other? If so, which is recommended? I have
[tim@helen etc]$ cat anacrontab
[ ... ]
[tim@helen etc]$ cat crontab
[ ... ]
I didn't write either of these, they must have been automatically installed.
My impression is that anacrontab was ignored until recently, but now as far as I can see both are being read and acted on.
Any enlightenment gratefully received.
Timothy Murphy
It is pretty "normal" to have them both on CentOS.
# rpm -qf /etc/crontab crontabs-1.10-8 # rpm -qf /etc/anacrontab anacron-2.3-45.el5
man 8 anacron
"DESCRIPTION Anacron can be used to execute commands periodically, with a frequency specified in days. Unlike cron(8), it does not assume that the machine is running continuously. Hence, it can be used on machines that aren’t running 24 hours a day, to control daily, weekly, and monthly jobs that are usually controlled by cron."
This should make obvious why there are both of the crontabs and in which situations anacron runs through his tab and when cron runs through his.
Regards
Alexander
Alexander Dalloz wrote:
It is pretty "normal" to have them both on CentOS.
# rpm -qf /etc/crontab crontabs-1.10-8 # rpm -qf /etc/anacrontab anacron-2.3-45.el5
man 8 anacron
"DESCRIPTION Anacron can be used to execute commands periodically, with a frequency specified in days. Unlike cron(8), it does not assume that the machine is running continuously. Hence, it can be used on machines that aren’t running 24 hours a day, to control daily, weekly, and monthly jobs that are usually controlled by cron."
This should make obvious why there are both of the crontabs and in which situations anacron runs through his tab and when cron runs through his.
Sorry, it's not at all clear to me. The machine in question is running all the time. Are you saying that anacron should be turned off in this case, presumably by "chkconfig anacron off"?
1) I didn't turn it on, so presumably anacron runs by default under CentOS.
2) As far as I can tell, the duplication only started recently, when I noticed that I was getting logwatch messages twice a day.
I have another CentOS-5.4 machine, which is also running all the time, and as far as I can see there is no duplication on that machine.
To repeat my question, is one meant to turn anacron off if the machine is running all the time? Or is anacron meant to determine this in some way? And if so, how?
Sorry, it's not at all clear to me. The machine in question is running all the time. Are you saying that anacron should be turned off in this case, presumably by "chkconfig anacron off"?
- I didn't turn it on, so presumably anacron runs by default under
CentOS.
- As far as I can tell, the duplication only started recently,
when I noticed that I was getting logwatch messages twice a day.
I have another CentOS-5.4 machine, which is also running all the time, and as far as I can see there is no duplication on that machine.
To repeat my question, is one meant to turn anacron off if the machine is running all the time? Or is anacron meant to determine this in some way? And if so, how?
Timothy Murphy
Hi Timothy,
let's take the case that you have a power failure or a scheduled maintenance with your system for instance in the early morning hours, from 03:00am - 05:00am. cron.daily is set by default to run at 04:02am. So in this case cron could not perform tasks like logwatch. logwatch will miss in such a case, *if* there wouldn't be anacron which takes over the task to run after the machine is up again (i.e. at 05:00am).
There is no need to deactivate or remove anacron. If your system runs all the time, then anacron will not come into play. If you got actions by anacron on one of your systems, then it either was off while cronjobs should have run or it was in single user mode.
How anacron handles jobs is documentend in "man 8 anacron". It uses timestamp files in /var/spool/anacron/ to control, when a job was last performed and whether it is pending.
Regards
Alexander
Alexander Dalloz wrote:
let's take the case that you have a power failure or a scheduled maintenance with your system for instance in the early morning hours, from 03:00am - 05:00am. cron.daily is set by default to run at 04:02am. So in this case cron could not perform tasks like logwatch. logwatch will miss in such a case, *if* there wouldn't be anacron which takes over the task to run after the machine is up again (i.e. at 05:00am).
Thanks for your response.
Actually, I wouldn't mind in the slightest if cron.daily failed to run because the machine was down at the nominated time. It is not as though my world depends on cron.daily running every day. I certainly would not run another program in case that happened.
How anacron handles jobs is documentend in "man 8 anacron". It uses timestamp files in /var/spool/anacron/ to control, when a job was last performed and whether it is pending.
Actually, "man 8 anacron" does not say that. It says "Anacron records the date in a special timestamp file", but it doesn't say where that file is.
I see that there are actually files /var/spool/anacron/cron.daily , etc, on my machine listing the last day anacron ran (20100311) But it seems that this information is not used, in my case, I don't know why.
As I said, this duplication seems to have started recently, and I have taken no action on this machine for months apart from running "sudo yum update", so I assume some update had this effect.
I have a second CentOS machine where this duplication does not occur, even though everything seems the same as on the first machine.
On Thursday 11 March 2010 16:17:13 Timothy Murphy wrote:
Alexander Dalloz wrote:
let's take the case that you have a power failure or a scheduled maintenance with your system for instance in the early morning hours, from 03:00am - 05:00am. cron.daily is set by default to run at 04:02am. So in this case cron could not perform tasks like logwatch. logwatch will miss in such a case, *if* there wouldn't be anacron which takes over the task to run after the machine is up again (i.e. at 05:00am).
Thanks for your response.
Actually, I wouldn't mind in the slightest if cron.daily failed to run because the machine was down at the nominated time. It is not as though my world depends on cron.daily running every day. I certainly would not run another program in case that happened.
You're world may not depend on it but those of us who run 10's of servers need a bit more reassurance. ;-)
How anacron handles jobs is documentend in "man 8 anacron". It uses timestamp files in /var/spool/anacron/ to control, when a job was last performed and whether it is pending.
Actually, "man 8 anacron" does not say that. It says "Anacron records the date in a special timestamp file", but it doesn't say where that file is.
They're in /var/spool/anacron. Three files cron.daily .weekly .monthly.
I see that there are actually files /var/spool/anacron/cron.daily , etc, on my machine listing the last day anacron ran (20100311) But it seems that this information is not used, in my case, I don't know why.
That's the date anacron was last run.
As I said, this duplication seems to have started recently, and I have taken no action on this machine for months apart from running "sudo yum update", so I assume some update had this effect.
Yum probaably updated anacron and set it to running
On my laptop
# rpm -qa --last | grep anacron gives cronie-anacron-1.4.3-4.fc12 Sat Feb 27 11:05:52 2010
So it was updated last on 27th Feb.
I have a second CentOS machine where this duplication does not occur, even though everything seems the same as on the first machine.
Tony
Tony Molloy wrote:
Actually, I wouldn't mind in the slightest if cron.daily failed to run because the machine was down at the nominated time. It is not as though my world depends on cron.daily running every day. I certainly would not run another program in case that happened.
You're world may not depend on it but those of us who run 10's of servers need a bit more reassurance. ;-)
The scenario is apparently that there is a power outage at exactly the time cron.daily is running. The machine stops and then starts again (if it doesn't then it doesn't matter whether anacron is running or not). In my experience the probability of this occurring is close to zero, and it wouldn't really matter if logrotate or something like that was put off for one night. What are you running through cron.daily on your 10's of servers that is so vital?
I see that there are actually files /var/spool/anacron/cron.daily , etc, on my machine listing the last day anacron ran (20100311) But it seems that this information is not used, in my case, I don't know why.
...
As I said, this duplication seems to have started recently, and I have taken no action on this machine for months apart from running "sudo yum update", so I assume some update had this effect.
On my laptop
# rpm -qa --last | grep anacron gives cronie-anacron-1.4.3-4.fc12 Sat Feb 27 11:05:52 2010
In my case,
[tim@helen ~]$ rpm -qa --last | grep anacron anacron-2.3-45.el5.centos Fri 07 Mar 2008 08:36:23 PM GMT
Note the year (2008). It seems anacron has not been updated for ages, although I run "yum update" every day.
I'll try turning off anacron on the first machine, and see what happens. The duplication issue is not really a problem - I just wondered (and wonder) why it is happening.
On 03/11/2010 10:17 AM, Timothy Murphy wrote:
Alexander Dalloz wrote:
let's take the case that you have a power failure or a scheduled maintenance with your system for instance in the early morning hours, from 03:00am - 05:00am. cron.daily is set by default to run at 04:02am. So in this case cron could not perform tasks like logwatch. logwatch will miss in such a case, *if* there wouldn't be anacron which takes over the task to run after the machine is up again (i.e. at 05:00am).
Thanks for your response.
Actually, I wouldn't mind in the slightest if cron.daily failed to run because the machine was down at the nominated time. It is not as though my world depends on cron.daily running every day. I certainly would not run another program in case that happened.
In that case feel free to disable anacron, but it really makes little difference. As Stephen has pointed out, in CentOS 5 anacron runs once when you enter any of the runlevels where it is active, runs any overdue {daily,weekly,monthly} jobs, and then exits. If there are no overdue jobs, anacron exits immediately.
BTW, don't try to apply this knowledge to more recent releases, such as Fedora 12. There, the interaction between cron and anacron is more complex. The standard setup there is for cron to run only the hourly jobs and for anacron, started each hour as one of those jobs, to run any needed {daily,weekly,monthly} jobs.
On Thursday 11 March 2010 12:50:13 Timothy Murphy wrote:
Is one meant to have one or the other? If so, which is recommended? I have
[tim@helen etc]$ cat anacrontab # /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root
1 65 cron.daily run-parts /etc/cron.daily 7 70 cron.weekly run-parts /etc/cron.weekly 30 75 cron.monthly run-parts /etc/cron.monthly
[tim@helen etc]$ cat crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/
# run-parts 01 * * * * root run-parts /etc/cron.hourly 02 4 * * * root run-parts /etc/cron.daily 22 4 * * 0 root run-parts /etc/cron.weekly 42 4 1 * * root run-parts /etc/cron.monthly
I didn't write either of these, they must have been automatically installed.
My impression is that anacrontab was ignored until recently, but now as far as I can see both are being read and acted on.
Any enlightenment gratefully received.
Both are typically installed as part of a CentOS install. But you only need one or the other. Generally cron on a 24x7 machine and anacron on a laptop. One or the otrher is mormally disabled.
cron is a fixed time schedular. I wakes up every minute and checks if there are any jobs to be run. It checks /etc'/crontab for system crons to run and also in /var/spool/cron for individual crons to be run.
e.g from my /etc/crontab file
22 4 * * 0 root run-parts /etc/cron.weekly
says
At 22 minutes past 4am run /etc/cron.weekly
anacron is for machines that are not up 24x7 so they could miss some of the times when "cron jobs" were to be run. So anacron wakes up and checks the /etc/anacrontab file. Then it runs any jobs after a certain delay period ( not at a fixed time )
e.g from my /etc/anacrontab file
7 20 cron.weekly nice run-parts /etc/cron.weekly
says
20 minutes after waking up every 7 days run /etc/cron.weekly
Hope this helps,
Tony
Tony Molloy wrote:
anacron is for machines that are not up 24x7 so they could miss some of the times when "cron jobs" were to be run. So anacron wakes up and checks the /etc/anacrontab file. Then it runs any jobs after a certain delay period ( not at a fixed time )
...
Hope this helps,
Sadly, no.
If "anacron is for machines that are not up 24x7" then why run it on machines that are up all the time (which I imagine is most CentOS machines)?
On Thursday 11 March 2010 16:00:49 Timothy Murphy wrote:
Tony Molloy wrote:
anacron is for machines that are not up 24x7 so they could miss some of the times when "cron jobs" were to be run. So anacron wakes up and checks the /etc/anacrontab file. Then it runs any jobs after a certain delay period ( not at a fixed time )
...
Hope this helps,
Sadly, no.
If "anacron is for machines that are not up 24x7" then why run it on machines that are up all the time (which I imagine is most CentOS machines)?
It's only on if you have switched it on.. # chkconfig --list | grep anacron
will tell you if it is switched on
# chkconfig --level 35 anacon off
will switch it off. on next rebot
# service anacron stop
will stop it immediatley.
You don't need it on a machine that's up 24x7. cron should handle all your scheduled jobs.
By the way I run centos on several of my laptops and they're not up 24x7
Tony
On Thu, Mar 11, 2010 at 04:52:56PM +0000, Tony Molloy wrote:
It's only on if you have switched it on.. # chkconfig --list | grep anacron
# chkconfig --level 35 anacon off
will switch it off. on next rebot
# service anacron stop
will stop it immediatley.
In fact, it's not that simple; anacron isn't a persistent daemon.
The way it works is that the rc script calls anacron to catch up on missed jobs. When anacron has finished this then it exits.
Now from regular cron you'll see /etc/cron.{daily,weekly,monthly}/0anacron which calls "anacron -u". This simply tells anacron to update the timestamp and does nothing else.
And that's how the boot version determines if there's work to do; if the timestamp file is too old at boot time.
During normal operation anacron shouldn't run (except for the timestamp updates). If it is then either it's been running since boot time (lots of work to catchup? hung?) or else it's been incorrectly started.
So $ chkconfig --list anacron anacron 0:off 1:off 2:on 3:on 4:on 5:on 6:off
$ service anacron status anacron is stopped
$ grep anacron /var/log/cron Mar 7 04:22:02 mercury anacron[3138]: Updated timestamp for job `cron.weekly' to 2010-03-07 Mar 8 04:02:02 mercury anacron[20530]: Updated timestamp for job `cron.daily' to 2010-03-08 Mar 9 04:02:02 mercury anacron[26657]: Updated timestamp for job `cron.daily' to 2010-03-09 Mar 10 04:02:03 mercury anacron[5804]: Updated timestamp for job `cron.daily' to 2010-03-10 Mar 11 04:02:01 mercury anacron[10005]: Updated timestamp for job `cron.daily' to 2010-03-11
Tony Molloy wrote:
If "anacron is for machines that are not up 24x7" then why run it on machines that are up all the time (which I imagine is most CentOS machines)?
It's only on if you have switched it on.. # chkconfig --list | grep anacron
will tell you if it is switched on
In my case, it is on (on both my CentOS machines) but I certainly did not turn it on. On one machine at least it must have been running since CentOS was installed.
By the way I run centos on several of my laptops and they're not up 24x7
Seems a strange distribution to me to run on a laptop. Don't you find you are missing some things?
In any case, surely CentOS is intended basically for servers, which are unlikely to be turned off very often?