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.
|
|
|
06-27-2017, 03:37 AM
|
#1
|
Member
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42
Rep:
|
ntp crontab duplicated
Hi everyone,
I'm configuring a crontab in my new host and it shows the following messages on the /var/log/cron:
Code:
Jun 27 06:07:01 SERVER CROND[12059]: (root) CMD (root /usr/sbin/ntpdate ntp0 > /dev/null 2>&1)
Jun 27 06:07:01 SERVER CROND[12060]: (root) CMD (/usr/sbin/ntpdate ntp0 > /dev/null 2>&1)
Jun 27 07:01:01 SERVER CROND[12641]: (root) CMD (run-parts /etc/cron.hourly)
Jun 27 07:01:01 SERVER run-parts(/etc/cron.hourly)[12641]: starting 0anacron
Jun 27 07:01:01 SERVER run-parts(/etc/cron.hourly)[12650]: finished 0anacron
as you can see, is executing two times...and I donīt know the reason...
my cron file is the following:
Code:
[root@SERVER cron.d]# cat /etc/cron.d/
0hourly ntp raid-check
[root@SERVER cron.d]# cat /etc/cron.d/ntp
#sincronize hour
#Linux system
7 * * * * root /usr/sbin/ntpdate ntp0 > /dev/null 2>&1
OS:
Red Hat Enterprise Linux Server release 6.9 (Santiago)
Permisions on the file:
Code:
-rw-r--r-- 1 root root 93 Jun 6 13:58 ntp
I check other hosts, not configuring by me, and show the following log:
Code:
Jun 27 05:00:01 SERVER crond[823]: (*system*) NULL security context for user, but SELinux in permissive mode, continuing ()
Jun 27 05:00:01 SERVER crond[824]: (root) CMD (/usr/sbin/ntpdate ntp0 >/dev/null)
Jun 27 05:01:01 SERVER crond[1713]: (*system*) NULL security context for user, but SELinux in permissive mode, continuing ()
Jun 27 05:01:01 SERVER crond[1714]: (root) CMD (run-parts /etc/cron.hourly)
Thank you in advance
|
|
|
06-27-2017, 05:37 AM
|
#2
|
LQ Veteran
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.5
Posts: 5,826
|
Quote:
Originally Posted by businesscat
Hi everyone,
I'm configuring a crontab in my new host and it shows the following messages on the /var/log/cron:
Code:
Jun 27 06:07:01 SERVER CROND[12059]: (root) CMD (root /usr/sbin/ntpdate ntp0 > /dev/null 2>&1)
Jun 27 06:07:01 SERVER CROND[12060]: (root) CMD (/usr/sbin/ntpdate ntp0 > /dev/null 2>&1)
Jun 27 07:01:01 SERVER CROND[12641]: (root) CMD (run-parts /etc/cron.hourly)
Jun 27 07:01:01 SERVER run-parts(/etc/cron.hourly)[12641]: starting 0anacron
Jun 27 07:01:01 SERVER run-parts(/etc/cron.hourly)[12650]: finished 0anacron
as you can see, is executing two times...and I donīt know the reason...
my cron file is the following:
Code:
[root@SERVER cron.d]# cat /etc/cron.d/
0hourly ntp raid-check
[root@SERVER cron.d]# cat /etc/cron.d/ntp
#sincronize hour
#Linux system
7 * * * * root /usr/sbin/ntpdate ntp0 > /dev/null 2>&1
[snip]
Thank you in advance
|
What is in /etc/cron.d/0hourly ?
|
|
|
06-27-2017, 07:07 AM
|
#3
|
Member
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42
Original Poster
Rep:
|
Quote:
Originally Posted by scasey
What is in /etc/cron.d/0hourly ?
|
this:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
01 * * * * root run-parts /etc/cron.hourly
|
|
|
06-27-2017, 07:20 AM
|
#4
|
Moderator
Registered: Aug 2002
Posts: 26,348
|
It looks like you have two separate cron jobs. Check roots cron jobs i.e.
crontab -l
|
|
|
06-27-2017, 07:29 AM
|
#5
|
Member
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42
Original Poster
Rep:
|
Quote:
Originally Posted by michaelk
It looks like you have two separate cron jobs. Check roots cron jobs i.e.
crontab -l
|
Code:
[root@HOST~]# crontab -l
# Sincro
# Linux
7 * * * * root /usr/sbin/ntpdate ntp0 > /dev/null 2>&1
only appear this cron
|
|
|
06-27-2017, 07:41 AM
|
#6
|
Moderator
Registered: Aug 2002
Posts: 26,348
|
You have two separate cron jobs running. One as the root user and one as a system job i.e. /etc/cron.d.
Delete the one running under root. You can use crontab -e.
In addition why are you running ntpdate versus ntp?
Last edited by michaelk; 06-27-2017 at 07:48 AM.
|
|
|
06-27-2017, 07:59 AM
|
#7
|
Member
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42
Original Poster
Rep:
|
Quote:
Originally Posted by michaelk
You have two separate cron jobs running. One as the root user and one as a system job i.e. /etc/cron.d.
Delete the one running under root. You can use crontab -e.
In addition why are you running ntpdate versus ntp?
|
I see, but one question:
How can I see where is the other crontab is defined?
If i use crontab -e appears the following:
Code:
# Sincro
# Linux
7 * * * * root /usr/sbin/ntpdate ntp0 > /dev/null 2>&1
If I comment the last line, I suppose it doesn't apply anymore...right? But...where is the other crontab defined?
More info:
I create this crontab with the following commands:
Code:
vim /etc/cron.d/ntp
contrab ntp
thank you so much, probably is a stupid thing but I canīt see that...too much hours with Windows...
|
|
|
06-27-2017, 08:17 AM
|
#8
|
Member
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42
Original Poster
Rep:
|
Quote:
Originally Posted by michaelk
In addition why are you running ntpdate versus ntp?
|
When I execute this ntpdate:
Code:
[root@HOSTcron.d]# /usr/sbin/ntpdate ntp0
27 Jun 14:16:16 ntpdate[48823]: adjust time server 10.59.172.47 offset -0.031481 sec
|
|
|
06-27-2017, 08:18 AM
|
#9
|
Moderator
Registered: Aug 2002
Posts: 26,348
|
One cron job is /etc/cron.d/ntp. This is a system cron job
Second cron job is under root user (crontab -l). This is a users cron job which are saved to /var/spool/cron by default.
ntpdate will force a time jump while ntp slowly adjusts time.
Last edited by michaelk; 06-27-2017 at 08:23 AM.
|
|
|
06-27-2017, 08:46 AM
|
#10
|
Member
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42
Original Poster
Rep:
|
Ok, Iīm (think) understand your point. Tomorrow I will test your advice.
Thank you so much for your patience.
Last edited by businesscat; 06-27-2017 at 08:47 AM.
|
|
|
06-27-2017, 11:38 AM
|
#11
|
LQ Veteran
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.5
Posts: 5,826
|
Quote:
Originally Posted by businesscat
this:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
01 * * * * root run-parts /etc/cron.hourly
|
What is in /etc/cron.hourly?
|
|
|
06-27-2017, 12:07 PM
|
#12
|
Moderator
Registered: Aug 2002
Posts: 26,348
|
Although we do not have all of the cron log entries and making a few assumptions but if the OP put their ntp script in cron.hourly there would be a log entry like.
Quote:
Jun 27 07:01:01 SERVER run-parts(/etc/cron.hourly)[12641]: starting ntp
Jun 27 07:01:01 SERVER run-parts(/etc/cron.hourly)[12650]: finished ntp
|
Quote:
Jun 27 06:07:01 SERVER CROND[12059]: (root) CMD (root /usr/sbin/ntpdate ntp0 > /dev/null 2>&1)
|
This would indicate a cron.d or a users cron job.
Quote:
(root /usr/sbin/ntpdate ntp0 > /dev/null 2>&1)
|
This is the command that cron will run. System cron jobs require a run as user but a regular user's does not.
Since root shows up in the command it typically means that there is a root cron job.
|
|
1 members found this post helpful.
|
06-27-2017, 01:53 PM
|
#13
|
LQ Veteran
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.5
Posts: 5,826
|
Quote:
Originally Posted by michaelk
This is the command that cron will run. System cron jobs require a run as user but a regular user's does not.
Since root shows up in the command it typically means that there is a root cron job.
|
Ahh. I wondered what the difference was between these:
Code:
Jun 27 06:07:01 SERVER CROND[12059]: (root) CMD (root /usr/sbin/ntpdate ntp0 > /dev/null 2>&1)
Jun 27 06:07:01 SERVER CROND[12060]: (root) CMD (/usr/sbin/ntpdate ntp0 > /dev/null 2>&1)
So the first indicates the user root's crontab, and the second is from /etc/cron.d/ntp -- right?
The OP is apparently logged in as root, so when he does he is seeing the second cron, yes?
Then he should probably just and delete that one. Agreed?
|
|
|
06-27-2017, 02:09 PM
|
#14
|
Moderator
Registered: Aug 2002
Posts: 26,348
|
Yes, however if the root cron job did not have "root" in the command then the log would look the same as the /etc/cron.d
|
|
|
06-28-2017, 02:53 AM
|
#15
|
Member
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42
Original Poster
Rep:
|
Quote:
Originally Posted by scasey
What is in /etc/cron.hourly?
|
This:
Code:
[root@HOST~]# cat /etc/cron.hourly/0anacron
#!/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
Quote:
Originally Posted by scasey
Ahh. I wondered what the difference was between these:
Code:
Jun 27 06:07:01 SERVER CROND[12059]: (root) CMD (root /usr/sbin/ntpdate ntp0 > /dev/null 2>&1)
Jun 27 06:07:01 SERVER CROND[12060]: (root) CMD (/usr/sbin/ntpdate ntp0 > /dev/null 2>&1)
So the first indicates the user root's crontab, and the second is from /etc/cron.d/ntp -- right?
The OP is apparently logged in as root, so when he does he is seeing the second cron, yes?
Then he should probably just and delete that one. Agreed?
|
I comment the line on crontab -e
Code:
#7 * * * * root /usr/sbin/ntpdate ntp0 > /dev/null 2>&1
and, on the log shows:
Code:
Jun 28 08:07:01 HOST CROND[60678]: (root) CMD (/usr/sbin/ntpdate ntp0 > /dev/null 2>&1)
Jun 28 08:47:58 HOST crontab[61109]: (root) BEGIN EDIT (root)
Jun 28 08:48:07 HOST crontab[61109]: (root) END EDIT (root)
Quote:
Originally Posted by michaelk
Yes, however if the root cron job did not have "root" in the command then the log would look the same as the /etc/cron.d
|
Thank you michalek
In your opinion, what is the best way to create a crontab?
I use the following:
Code:
vim /etc/cron.d/ntp
add to the file:
7 * * * * root /usr/sbin/ntpdate ntp0 > /dev/null 2>&1
contrab ntp
Thank you, by the moment the log shows:
Code:
Jun 28 08:07:01 HOST CROND[60678]: (root) CMD (/usr/sbin/ntpdate ntp0 > /dev/null 2>&1)
Jun 28 08:47:58 HOST crontab[61109]: (root) BEGIN EDIT (root)
Jun 28 08:48:07 HOST crontab[61109]: (root) END EDIT (root)
|
|
|
All times are GMT -5. The time now is 09:06 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
|
|