CentOSThis forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am running CentOS release 6.6 (Final)
I have a cron daily running:
Code:
02 4 * * * root run-parts /etc/cron.daily
I have a backup cron running which sends me an email every day to inform me that it has run, but I get 2 occurrences of it:
Quote:
root 04:02 ASHBARN fileserver backup run
root 04:02 ASHBARN fileserver backup run
If I change the backup.cron to chmod 644, it stops working altogether. I don't get any email notification at all.
Can anybody advise me why this is, and where the second occurrence is running from.
It depends on how your computer is configured but by default CentOS 5 runs cron.daily at 4:02 as posted but CentOS 6 uses anacron (/etc/anacrontab). Is backup.cron something you created yourself?
Hopefully this may help in finding the answer.
As far as I know, all the cron jobs run from /etc/crontab
Is there anywhere else where cron jobs can run from ??
Hi Michealk..
Thanks for taking the time to reply.
Quote:
It depends on how your computer is configured but by default CentOS 5 runs cron.daily at 4:02 as posted but CentOS 6 uses anacron (/etc/anacrontab). Is backup.cron something you created yourself?
I don't have /etc/anacrontab on my computer, so the problem isn't that.
YES. backup.cron is created by me.
Here it is:
I don't have /etc/anacrontab on my computer, so the problem isn't that.
Is that because you removed it? anacron is installed by default in CentOS 6, and the cron daemon has dependencies on it.
Look in /etc/cron.d/ and see of some file in there is running anything that would also start jobs in /etc/cron.daily/ . Among other things, the default /etc/cron.d/0hourly will try to run jobs in /etc/cron.hourly, and there the /etc/cron.hourly/0anacron will try to start anacron, and I don't know what that's going to do in the absence of the /etc/anacrontab config file.
Is that because you removed it? anacron is installed by default in CentOS 6, and the cron daemon has dependencies on it.
No. I haven,t removed it. In fact it is a relatively new installation.
I have just run yum install -y anacron and I now have anacrontab.
I will let it run overnight and see what happens
I have checked /etc/cron.d/0hourly and it just wants to run 01 * * * * root run-parts /etc/cron.hourly
I wouldn't expect that installing anacron would help the situation -- might make it worse. I was just surprised that it wasn't already installed. I subsequently dug around and found the "cronie-noanacron" package, which would give you just the traditional cron behavior and does not have anacron as a dependency.
Have you looked in /var/log/cron for some clue as to how the two jobs were getting started?
I don't understand what all this code means, but here is /etc/cron.hourly/0anacron
Code:
#!/bin/bash
# Skip excecution unless the date has changed from the previous run
if test -r /var/spool/anacron/cron.daily; then
day=`cat /var/spool/anacron/cron.daily`
fi
if [ `date +%Y%m%d` = "$day" ]; then
exit 0;
fi
# Skip excecution unless AC powered
if test -x /usr/bin/on_ac_power; then
/usr/bin/on_ac_power &> /dev/null
if test $? -eq 1; then
exit 0
fi
fi
/usr/sbin/anacron -s
Hopefully you will understand this code and be able to tell me if this is what is starting the second backup.cron.
Are you also running cron.daily from somewhere else? Your original post did not say where you had that crontab entry, and anyway the one you showed is not the same as the entry in /etc/cron.d/dailyjobs.
If you're going to use anacron you should uninstall cronie-noanacron and replace it with cronie-anacron.
Hi rknichols...
Thank you for the trouble that you are going to to try and help me.
I have been testing various combinations, without much success.
However, the computer that is causing some concern is remote to me, and has closed down. I can't get into it to check anything.
I will continue when it is switched back on.
Meanwhile, can you tell me how I can run crontab contents, from crontab, as if it were in the normal course of events?
Regards,
Meanwhile, can you tell me how I can run crontab contents, from crontab, as if it were in the normal course of events?
I'm not quite sure what you are asking. You can, for the most part, take the command portion of a crontab entry and give it to a shell run under the appropriate UID, but you can't easily duplicate the exact environment under which a cron job runs. The way I generally handle the manual triggering of a cron job is by temporarily modifying the crontab entry so that the job runs 2 minutes from now**, and then restore the original crontab afterward.
** The cron daemon will load the modified crontab when time rolls over to the next minute, but it does this after starting jobs for the current cycle. The first opportunity for running a new job will be the second time a minute rolls over. It's done that way so that you can have a cron job that modifies the crontab without causing an infinite loop.
The way I generally handle the manual triggering of a cron job is by temporarily modifying the crontab entry so that the job runs 2 minutes from now**, and then restore the original crontab afterward.
Thanks for your suggestion. I didn't think of that, but it would do what I want it to do.
However, my client is now on holiday until the end of next week, and his server or router, is down.
I will resume when he gets back.
Regards,
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.