Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
|
09-18-2015, 07:56 AM
|
#1
|
LQ Newbie
Registered: Sep 2015
Posts: 16
Rep:
|
Cron job starts 6 hours late, rest of cron jobs work fine
Hi all,
I am a sysadmin, but I mostly have experience in Windows.
Since Linux is much more attractive to businesses I'm now learning the ropes.
At my workplace we use Ubuntu 14.04 (we have around 7/8 linux servers), and we have a set of cron jobs that are executed everyday around midnight (01:00 or 01:30), but one machine in particular executes the cron jobs way too late (it begins around 07:30).
I already searched in dmesg, an in /var/log/syslog, but I'm not getting any wiser. I also Googled the problem, and various sites tell me that the timezone may be set-up wrong, but that's not the case.
Here I'll give an example of the output of the "date" command.
The first output is from the server in question with the cron problem:
root@caccini:/var/log# date
Fri Sep 18 14:46:54 CEST 2015
and a few moments later:
phouwen@encina:~$ date
Fri Sep 18 14:47:19 CEST 2015
Can anyone assist me or point me in the right direction?
(I also found that maybe if I ran "date -u", it would give a diffirent time, so here it goes:
root@caccini:/etc# date -u
Fri Sep 18 12:54:58 UTC 2015
phouwen@encina:~$ date -u
Fri Sep 18 12:55:03 UTC 2015
)
Thanks!
Last edited by pieterhouwen; 09-18-2015 at 08:15 AM.
|
|
|
09-18-2015, 08:30 AM
|
#2
|
Member
Registered: Jul 2003
Posts: 363
Rep:
|
A couple of things offered for consideration:
1) are you editing the crontab file that is actually being used by cron, and did you restart cron after editing crontab to make it read the changes ?
2) are you aware that: if a user was not allowed to execute jobs when their crontab was last edited (ie. user was not listed in cron.allow),
then the user needs to be added to cron.allow AND THEN crontab needs to be re-edited to allow that user's jobs to execute, and CRON needs to be restarted to pickup the changes.
3) do you have a process running on the ssytem around that time, that is actually blocking the scrip from executing ?
I suggest that you write a quick script that dumps the date/time, and add that job to crontab, then restart cron (to pick up the job changes).
Use that approach to ensure that the job is starting at the correct system time. (Definitive evidence).
Even consider adding a dup of the active processes to that script.
If you have a mis-match between the crontab scheduled job time and the execution of the test job then you have your answer.
C.
|
|
|
09-18-2015, 09:34 AM
|
#3
|
Senior Member
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,950
|
If you use the approved way of editing your crontab i.e. by using the crontab command, there should be no need to restart anything.
crontab -l from the appropriate user will display your settings - perhaps you mistyped a setting?
date gives your local time, including DST.
date -u gives the UTC time.
Last edited by JeremyBoden; 09-18-2015 at 09:39 AM.
|
|
|
09-18-2015, 10:29 AM
|
#4
|
Member
Registered: Jul 2003
Posts: 363
Rep:
|
JeremyBoden
Eeek!
(Smiles) Point taken. But I am a purist and prefer to edit crontab directly.
C.
|
|
|
09-28-2015, 05:04 AM
|
#5
|
LQ Newbie
Registered: Sep 2015
Posts: 16
Original Poster
Rep:
|
Hi all, thanks for your quick reply.
Executing "crontab -l" gives me the following:
root@caccini:/etc# crontab -l
no crontab for root
While "nano /etc/crontab" gives me:
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
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 )
#
Any suggestions?
|
|
|
09-28-2015, 06:28 AM
|
#6
|
Senior Member
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
|
crontab -l lists the cron jobs of the active user.
the /etc/crontab files are system wide cron jobs. Mostly used by services. Also logrotate run through the crontab settings (should be /etc/cron.daily).
Check out the directories given and see which cronjobs are there. Guess /etc/cron.daily is where yours are hiding. Coming from the time you wrote in your first post.
As your settings for cron.daily is scheduled for the first hour of the day (01 0 * * *) you need to check why some jobs are run at 1:30 (also taken from your first post). Either the crontab was edited or there is a sleep 1800 at the start of the scripts to have it sleep for half a hour and then go to work. Maybe someone used this method but did the math wrong? grep "sleep" /etc/cron.* for a quick hint.
Can you post the time of the systems that are running correctly. Just to be sure that the time is good on all systems. Maybe use ntp on all machines?
|
|
|
09-28-2015, 06:36 AM
|
#7
|
Senior Member
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,950
|
What user did you create the crontab for?
Try
Code:
sudo crontab -u username -l
(where username is the user who you specified the crontab for).
I've never tried to get root to run crontab jobs via the crontab mechanism - its a bit insecure isn't it?
However, root will run the scripts in /etc/cron.daily on a daily basis.
Similarly for hourly(?), weekly & monthly - it isn't usually time-critical as to when a root job is run.
|
|
|
09-28-2015, 06:41 AM
|
#8
|
LQ Newbie
Registered: Sep 2015
Posts: 16
Original Poster
Rep:
|
Grep "sleep" /etc/cron.* did not give me any useful information:
root@caccini:/etc# grep "sleep" cron.*
grep: cron.d: Is a directory
grep: cron.daily: Is a directory
grep: cron.hourly: Is a directory
grep: cron.monthly: Is a directory
grep: cron.weekly: Is a directory
root@caccini:/etc#
I can't seem to figure out why. Also, I'm gonna edit the title of this post seeing as it's not only that one cron job that doesn't start at specified time, but all of them. (although there are some differences in how much too late they run.
And Jeremy, the specified command didn't give any valuable output:
root@caccini:~# crontab -u root -l
no crontab for root
---------- Post added 09-28-15 at 01:42 PM ----------
Last edited by pieterhouwen; 09-28-2015 at 06:43 AM.
|
|
|
09-28-2015, 06:46 AM
|
#9
|
LQ Newbie
Registered: Sep 2015
Posts: 16
Original Poster
Rep:
|
I can't seem to find an option which enables me to change the title of the thread. Perhaps I'm overlooking something?
|
|
|
09-28-2015, 10:14 AM
|
#10
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
Quote:
Originally Posted by pieterhouwen
root@caccini:~# crontab -u root -l
no crontab for root
|
Then it sounds like root doesn't have a crontab. How exactly did you add this command to the cron?
Last edited by suicidaleggroll; 09-28-2015 at 10:15 AM.
|
|
|
09-28-2015, 10:15 AM
|
#11
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
Quote:
Originally Posted by JeremyBoden
I've never tried to get root to run crontab jobs via the crontab mechanism - its a bit insecure isn't it?
|
I don't see why it would be. Could you share why you think it would be a problem?
|
|
|
09-28-2015, 10:46 AM
|
#12
|
Senior Member
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,950
|
The crontab implementation either runs as a non-root user that is able to gain access to run as root
or crontab runs as a root daemon that can safely start non-root user applications.
Either way, running arbitrary commands/scripts by a process that switches its effective user name seems a little bit fraught?
BTW says, in part...
Quote:
If the /etc/cron.allow file exists, then you must be listed (one user per line) therein in order to be allowed to use
this command. If the /etc/cron.allow file does not exist but the /etc/cron.deny file does exist, then you must not be
listed in the /etc/cron.deny file in order to use this command.
If neither of these files exists, then depending on site-dependent configuration parameters, only the super user will be
allowed to use this command, or all users will be able to use this command.
If both files exist then /etc/cron.allow takes precedence. Which means that /etc/cron.deny is not considered and your
user must be listed in /etc/cron.allow in order to be able to use the crontab.
Regardless of the existance of any of these files, the root administrative user is always allowed to setup a crontab.
For standard Debian systems, all users may use this command.
|
|
|
|
09-29-2015, 02:58 AM
|
#13
|
LQ Newbie
Registered: Sep 2015
Posts: 16
Original Poster
Rep:
|
Quote:
Originally Posted by suicidaleggroll
Then it sounds like root doesn't have a crontab. How exactly did you add this command to the cron?
|
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?
|
|
|
09-29-2015, 03:05 AM
|
#14
|
LQ Newbie
Registered: Sep 2015
Posts: 16
Original Poster
Rep:
|
Quote:
Originally Posted by pieterhouwen
Grep "sleep" /etc/cron.* did not give me any useful information:
root@caccini:/etc# grep "sleep" cron.*
grep: cron.d: Is a directory
grep: cron.daily: Is a directory
grep: cron.hourly: Is a directory
grep: cron.monthly: Is a directory
grep: cron.weekly: Is a directory
root@caccini:/etc#
|
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
After looking at the code of apt a little more I see:
# sleep for a random interval of time (default 30min)
# (some code taken from cron-apt, thanks)
random_sleep()
{
RandomSleep=1800
eval $(apt-config shell RandomSleep APT::Periodic::RandomSleep)
if [ $RandomSleep -eq 0 ]; then
return
fi
Could this be the source of the problems?
|
|
|
09-29-2015, 03:22 AM
|
#15
|
Senior Member
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,950
|
No.
You have a cron job (called apt) that appears to be trying to run roughly every 30 minutes.
Many cron jobs can run simultaneously.
|
|
|
All times are GMT -5. The time now is 11:36 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|