?
Solved

Cron Job not successful on Linux (SLES 10)

Posted on 2014-11-26
9
Medium Priority
?
284 Views
Last Modified: 2014-11-27
Hi,

We had a Linux Expert setup a Cron Job for us on a Linux Server, it makes the Server sync it's time with a time server on the Internet once a minute as there's an issue whereby it wins time and needs to be updated once a minute.

The funny thing is that the Cron Job does not work,

If I run crontab -e it's got * * * * *  ntpdate -u 196.25.1.9 on the one line which should make it sync with that time server once a minute.

If I tail the crontab it shows the following:

Nov 26 10:11:01 mail /usr/sbin/cron[18596]: (root) CMD (ntpdate -u 10.51.158.132)
Nov 26 10:12:01 mail /usr/sbin/cron[18678]: (root) CMD (ntpdate -u 10.51.158.132)

So I can see that the Cron Job is running correctly, but it does not actually update the time (Server keeps on winning time).

If I enter the command manually on the Server (
ntpdate -u 196.25.1.9
) then it updates immediately and the time is fine.

Any assistance as to why that same command on the Cron Job is not updating the time would be of great assistance.

Thanks,
Reinhard
0
Comment
Question by:ReinhardRensburg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40466494
Looks to me like the wrong IP address.  10.51.158.132 (which is a local IP address) instead of 196.25.1.9 which is 'sangoma.saix.net'.
0
 
LVL 23

Expert Comment

by:savone
ID: 40466608
Using ntpdate t sync time is a terrible idea and a "Linux Expert" should know that.  

ntpd is a daemon designed to sync time.  The algorithms it uses are much more efficient at keeping a clock synced with a valid time source. You can find hundreds of articles on why this is true.

ntpdate is good to set the initial time sync, or to sync during boot, then ntpd should be used from that point on.

A quick google search found these:

http://askubuntu.com/questions/297560/ntpd-vs-ntpdate-pros-and-cons

http://serverfault.com/questions/16467/compare-ntpd-and-ntpdate

You can find many more.

Even wikipedia calls ntpdate deprecated.

http://en.wikipedia.org/wiki/Ntpdate
0
 

Author Comment

by:ReinhardRensburg
ID: 40466721
Hi Dave Baldwin, thanks for your reply. The IP Address used at the moment in the Cron Job is just an internal time server (we tried both internal and external time servers - it fails to update time in both instances, so the IP Address is really irrelevant in this case),

Hi savone, thanks for your comments as well, this is a virtual SLES 10 Server running on Microsoft Hyper-V. The Linux Expert that helped us first looked at ntpd and tried to get the Server to use that to set the time, what he found (by using all kinds of fancy techniques) was that the Server's time compared to a stop watch is out, the server counts 30 seconds when in real life only 26.4 seconds has passed, so what the expert advised was that when using ntpd (that gradually adjusts the time) the drifting is so fast that it cannot catch up with the server's time running "too fast" so it still goes out, for this reason he suggested we use the ntpdate in a Cron Job to "instantly correct" the time every 1 minute.

So to summarise, we've tried all the available options and they did not work, and I am now trying to work out why the ntpdate command works when I enter it manually, but it does not work in the Cron Job even thought when tailing the cron tab log it does show that the server is executing that command ever 1 minute...

Our Linux Expert explained the initial issue (not getting ntpd to work) in a lot of detail, but unfortunately it's in a different language (Afrikaans) so I doubt if it would help if I post his e-mail :)

Thanks for any further advice.

Regards,
Reinhard
0
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 19

Assisted Solution

by:jools
jools earned 600 total points
ID: 40467051
Does Microsoft Hyper-V have something similar to vmtools on VMWare. I believe clock skew is quite common in  VM guests and we used to install the vmware tools as it helped out with the time differences (a bit).

Does any information get logged into the messages file?

Can you try using `ntpdate -u 196.25.1.9 >> /var/log/ntpdate.log 2>&1`to see if anything else gets logged?
0
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 1400 total points
ID: 40467160
In cron jobs, you always should use the full path to your programs, so can you change:

ntpdate

to:

/usr/sbin/ntpdate

(or the path where your ntpdate is located, find it with "which ntpdate")
0
 

Author Closing Comment

by:ReinhardRensburg
ID: 40468554
Thanks a lot Gerwin Jansen, you were spot on! By adding the full path to the ntpdate did the trick and it worked immediately.

Thanks to you too jools, the logging to a .log file also helped me confirm that it was indeed working and I got entries like the below in that log file:

"27 Nov 10:19:49 ntpdate[8087]: adjust time server 196.25.1.9 offset -0.228987 sec
27 Nov 10:19:58 ntpdate[8121]: step time server 196.25.1.9 offset -2.351268 sec
27 Nov 10:20:53 ntpdate[8183]: step time server 196.25.1.9 offset -8.194310 sec
27 Nov 10:20:53 ntpdate[8189]: adjust time server 196.25.1.9 offset -0.029993 sec
27 Nov 10:21:00 ntpdate[8221]: step time server 196.25.1.9 offset -0.821607 sec
27 Nov 10:21:54 ntpdate[8399]: step time server 196.25.1.9 offset -7.777917 sec"

Thanks again, I really appreciate it.

Reinhard.
0
 
LVL 19

Expert Comment

by:jools
ID: 40468564
As a bit of a cleanup, you can either move the log file to /var/log/messages (or whatever the main log file is in SLES) so it gets rotated, or remove the logging. You can always add it back if you need to.

Running it every minute will fill up the logs then you'll be posting back here about disk space. :-)

Ideally you should be looking to swap over to ntpd at some point.


Jools
0
 

Author Comment

by:ReinhardRensburg
ID: 40468572
Thanks a lot for the advice Jools,

I did remove the logging part in the crontab after I could confirm that it's working now.

You're quite right, the logs can cause quite a bit of chaos with Disk Space :)

Reinhard.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40468599
You're welcome ;)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month15 days, 11 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question