Cron job starts 6 hours late, rest of cron jobs work fine
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
01 0 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 4 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 5 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
What jobs are starting late?
In a nutshell the system cron jobs (daily, weekly, monthly) are configured such that if the computer is not running 24/7 they will run no matter what via anacron vs crond. I can only guess that with this particular server something between anacron and crond is not configured like the others.
Have you verified that crond is running? Is cron.hourly running?
In a nutshell the system cron jobs (daily, weekly, monthly) are configured such that if the computer is not running 24/7 they will run no matter what via anacron vs crond. I can only guess that with this particular server something between anacron and crond is not configured like the others.
Have you verified that crond is running? Is cron.hourly running?
I re-ran the command a little different now, output is below:
root@caccini:/etc# grep "sleep" cron.*/*
cron.daily/apt:# sleep for a random interval of time (default 30min)
cron.daily/apt:random_sleep()
cron.daily/apt: debug_echo "sleeping for $TIME seconds"
cron.daily/apt: sleep $TIME
cron.daily/apt:# sleep random amount of time to avoid hitting the
cron.daily/apt:random_sleep
Could this be the source of the problems?
The sleeping interval within apt cronjob is total okay. It makes sure that the apt system is not overrun with simultaneous access. And it only affects this single cronjob.
@Jeremy The apt cronjob only runs once through /etc/cron.daily. It just has this random sleep thing which is max 30 minutes.
Recheck the times. Once at the failing system and right after or before on a working system.
One can also set a timezone for cron specificly. Check out /etc/default/cron for a TZ stanca. As well as /etc/crontab which we already have and its not in there.
Also check out /etc/timzeone for the correct zone. Or the enviroment variable CRON_TZ and TZ itself.
Code:
printenv | grep -i tz
Also restart the cron daemon after fiddeling with timezone and date settings.
Have you checked the log files to see if cron.hourly is running?
Looks like anacron is running the cron.daily job as you posted.
Have you compared the other servers? Are they configured the same?
Yeah, I checked the other servers and they are now showing the same symptoms.
I did went back through my emails (I get a notification once a cron job completes), and the bug started after May 13th. The subject of the email also changed then.
It was (when the cron jobs were running as expected) "Cron <root@caccini> test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )" , but now it's "Anacron job 'cron.daily' on caccini" and the sender also changed from root@caccini to Anacron.
I have no idea what happened, I wasn't working with linux back then.
Any idea how to change this back?
So basically anacron is set to start at 7:30 and cron.daily via anacrontab will start after a 5 minute delay (7:35) which is what you see in your post #20. As far as I know this is the default configuration. By the way anacron will also start at boot up. Not enough information to know what changed.
If anacron is not executable then the cron job will run at the time indicated
Quote:
01 0 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
The ananacron is a red herring - it's a just a useful variant of cron.
My /etc/crontab contains
Code:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
Note:- at boot-up cron runs anacron and cron.hourly, /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly at the appropriate times
and any other crontab commands you have placed in /etc/crontab.
So I suggest you add your database backup script to /etc/crontab
Read man cron as there are some particular restrictions about script authorities (probably already met).
The ananacron is a red herring - it's a just a useful variant of cron.
My /etc/crontab contains
Code:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
Note:- at boot-up cron runs anacron and cron.hourly, /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly at the appropriate times
and any other crontab commands you have placed in /etc/crontab.
So I suggest you add your database backup script to /etc/crontab
Read man cron as there are some particular restrictions about script authorities (probably already met).
So if I understand correctly you're suggesting something like this?
Instead of
01 0 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily
Actually I didn't. It was already setup when I started working at the company. How can root have no crontab while in /etc/crontab every cron job is run by root?
Cron jobs are run by the service "crond". Anyone permitted may have a crontab file run.
A small assumption "Unlike cron, it does not assume that the system is running continuously."
This is only significant for jobs that would get skipped because something like a laptop might be down/suspended for a day or two.
When the system resumes the jobs that would have been skipped get run. Useful for things like log file rotation and general maintenance functions.
The standard cron service doesn't run those - under the assumption that the time they run is important (like always running accounting jobs at midnight so that the daily log/reports gets handled properly).
The choice between them is mostly up to the administrator to decide which is more important.
cron will run a particular task at the desired time/date but can not recover if the computer is off. Most maintenance tasks are typically run at odd hours of the night so if the computer is not on 24/7 they will never run.
anacron is designed to run daily, weekly or monthly jobs not by hours but by period and delay time. So maintenance tasks will run regardless if the computer is run 24/7 or not.
anacron will run at startup or at the scheduled hour defined by
/etc/cron.d/anacron
Might be easier to change from 7:30 to whenever you desire.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.