Solved

Cron Job not successful on Linux (SLES 10)

Posted on 2014-11-26
9
275 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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 82

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
 
LVL 19

Assisted Solution

by:jools
jools earned 150 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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 37

Accepted Solution

by:
Gerwin Jansen earned 350 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 37

Expert Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now