Solved

Cron Job not successful on Linux (SLES 10)

Posted on 2014-11-26
9
279 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 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

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

Accepted Solution

by:
Gerwin Jansen, EE MVE 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 38

Expert Comment

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

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which is more secure: EAP or machine certificate for IKEv2 VPN? 1 134
winscp 000webhost.com 6 73
ignore other .htaccess 2 58
How to mount nfs share on this CentOS server? 6 42
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
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.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

856 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