LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 06-27-2017, 02:37 AM   #1
businesscat
Member
 
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42

Rep: Reputation: Disabled
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
 
Old 06-27-2017, 04:37 AM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,441

Rep: Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070
Quote:
Originally Posted by businesscat View Post
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 ?
 
Old 06-27-2017, 06:07 AM   #3
businesscat
Member
 
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
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
 
Old 06-27-2017, 06:20 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,618

Rep: Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176
It looks like you have two separate cron jobs. Check roots cron jobs i.e.
crontab -l
 
Old 06-27-2017, 06:29 AM   #5
businesscat
Member
 
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
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
 
Old 06-27-2017, 06:41 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,618

Rep: Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176
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 06:48 AM.
 
Old 06-27-2017, 06:59 AM   #7
businesscat
Member
 
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
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...
 
Old 06-27-2017, 07:17 AM   #8
businesscat
Member
 
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post

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
 
Old 06-27-2017, 07:18 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,618

Rep: Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176
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 07:23 AM.
 
Old 06-27-2017, 07:46 AM   #10
businesscat
Member
 
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42

Original Poster
Rep: Reputation: Disabled
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 07:47 AM.
 
Old 06-27-2017, 10:38 AM   #11
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,441

Rep: Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070
Quote:
Originally Posted by businesscat View Post
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?
 
Old 06-27-2017, 11:07 AM   #12
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,618

Rep: Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176
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.
Old 06-27-2017, 12:53 PM   #13
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,441

Rep: Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070
Quote:
Originally Posted by michaelk View Post
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
Code:
crontab -l
he is seeing the second cron, yes?
Then he should probably just
Code:
crontab -e
and delete that one. Agreed?
 
Old 06-27-2017, 01:09 PM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,618

Rep: Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176Reputation: 4176
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
 
Old 06-28-2017, 01:53 AM   #15
businesscat
Member
 
Registered: Jun 2017
Location: Spain
Distribution: RedHat 6.9 /Centos 8
Posts: 42

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
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 View Post
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
Code:
crontab -l
he is seeing the second cron, yes?
Then he should probably just
Code:
crontab -e
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 View Post
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)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
NTP Server Using the NTP Time not External Servers or Pools jackgun Red Hat 3 11-04-2016 02:37 PM
[SOLVED] some issues with CentOSv7 and NTP with timedatectl set-ntp yes lleb Linux - Server 3 03-30-2015 08:45 PM
ntp client is not syncing with ntp server time sagar666 Linux - Server 3 12-19-2014 04:47 AM
[SOLVED] NTP configuration in client to synchronize with NTP server. antnish Linux - General 12 04-01-2013 01:49 PM
ntp drift file in /etc/ntp instead of /var/lib/ntp - suggestion for a patch in Slack niels.horn Slackware 16 05-07-2009 07:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration