Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cron not running rdate

Status
Not open for further replies.

NewtownGuy

Technical User
Jul 27, 2007
146
US
Hello,

I'm trying to have a number of Linux servers have the same time. I'm running (old) Fedora Core 2 and Fedora Core 3. In /etc/cron.hourly/, I have a file, set_time, with these contents:

Code:
#!/bin/sh

#rdate -s time.nrc.ca
rdate -s 132.246.168.148

I have set the permissions for this little script to 757.

The problem is that rdate does not seem to be running. When I purposely set the time to a few minutes fast, and wait an hour or two, the time is not set to the correct time. I know the IP address of the time server is ok because if I run the rdate line from the command line as root, the time gets updated correctly immediately.

How do I make the time update correctly ? Is there a better way to have multiple machines have the same time ?

Thank you.

-- NewtownGuy
 
Is it producing any error messages? Try redirecting the output of the cron job to a file, or checking root's mailbox to see if it's already in there. Perhaps rdate isn't in the default path used by cron jobs?

Annihilannic.
 
I think Annihilannic is probably correct - try replacing rdate with the fully qualified /path/to/rdate.

I want to be good, is that not enough?
 
Thank you.

I checked /var/spool/mail/root, and sure enough, there's an error message there about rdate:

Code:
/usr/bin/run-parts= /etc/cron.hour/set_time: /bin/sh^M: bad interpreter: No such file or directory

How do I find out where rdate lives ? I know it's there somewhere because I can run it from the command line, but I looked in several folders, including /bin/sh, and could not find it.

Separately, I enabled ntpd in setup, and it seems to be working. But I'd still like to know an easy way to find the location of executables...

-- NewtownGuy
 
easy way to find the location of executables...
The which-command shows the path to the command:
Code:
me@myPC:/$ which tuxtype
/usr/games/tuxtype

And
Code:
echo $PATH
will show what directories are searched when you type in
a command for execution.

 
TO: geirendre

The 'which' command is not present on my Fedora Core 3 machine. Is there an alternate command ?

-- NewtownGuy
 
Try using the locate command

$ locate rdate

On my RHEL4 instance i found rdate under /usr/bin

 
The /bin/sh^M might indicate a problem with the script, ie it seems to have 'DOS' CR/LF (^M) line-endings, when it requires a 'unix' LF only (if I recall correctly, not at work at the moment). Try running the file through dos2unix or equivalent (if supported), or edit yourself andd strip out all ^M characters.

Hope this helps - let us know how you get on!

I want to be good, is that not enough?
 
To find something, try:
Code:
find / -name "object" -print
where object is a character string like rdate; the "object" string is a regexp expression, so you may or may not need the quotes. In your case:
Code:
find / -name rdate -print

The cron script I run to set the system clock is:
Code:
/usr/sbin/rdate -s "server" && /sbin/hwclock -w
This sets the clock in the OS, then pipes the result to synch the hardware clock to it. The "server" value (without quotes) is usually either our internal GPS time server or a secondary or tertiary Internet time server (e.g. clock.psu.edu).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top