date and time automaticly

hi,

i have created a script “datetime”:

#/bin/sh
ntpdate de.pool.ntp.org

and put it in /etc/cron.hourly but it is not working. seems like it has never run.

any ideas what i can do to?

BiLL

That’s the wrong format for a crontab file. It should be something like this:

14 * * * * root ntpdate -s de.pool.ntp.org

i.e. 14 minutes past every hour, and you should put it in /etc/cron.d so that it isn’t wiped out when you upgrade the system, as cron.hourly is for system crontabs. cron.d is for local mods.

The -s is so that the output goes to syslog instead of stdout and getting emailed to root.

Better still, if you have an always-on connection is to set up a local NTP server to keep sync with NTP masters. There’s a YaST tool to configure that.

so, you mean i just have to create a file with that entry and put it in cron.d?

14 * * * * root ntpdate -s de.pool.ntp.org

is that right?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Show the cron entry in its entirety. Also does this work when run
manually? Do you have any other NTP clients running because, if so,
you’ll want to add a ‘-u’ option into the ntpdate command.

Good luck.

BiLL TuEr wrote:
| hi,
|
| i have created a script “datetime”:
|
| #/bin/sh
| ntpdate de.pool.ntp.org
|
| and put it in /etc/cron.hourly but it is not working. seems like it has
| never run.
|
| any ideas what i can do to?
|
| BiLL
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIhs4Q3s42bA80+9kRAhrkAJ4/jKI0yMaP9Q4wmoFdIWFqXE0uqwCfXEKV
eglenZ+6/+feUHvlpBzd9nA=
=7Faw
-----END PGP SIGNATURE-----

That’s right, call it something like ntpsync. And ab@novell.com is correct, if you have a NTP server running you should add the -u flag, although if you have a NTP server running, you wouldn’t need this job.

hehe, sorry. seems like my script was not executable by no one :slight_smile:

greetz

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Well, the command ken yap posted should be put in something like
/etc/crontab directly. Your script should go in /etc/cron.hourly and
then run properly. Have you tested it yet on its own? How do you know
it is not working? Any reason you don’t use the NTP client built into SUSE?

Good luck.

BiLL TuEr wrote:
| so, you mean i just have to create a file with that entry and put it in
| cron.d?
|
| 14 * * * * root ntpdate -s de.pool.ntp.org
|
| is that right?
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIhtQH3s42bA80+9kRAqokAJ0U1iZILTvUBEUSBMmB+42aIouKNQCdEuwM
17q+b6scl8mtvers5kcmv5o=
=siRX
-----END PGP SIGNATURE-----

i have tested it manualy and checked that the file was not executable. now it should work. in one hour i will have a look in syslog to see if it works now.

i did it my way and put the file in /etc/cron.hourly.

greetz

No, there’s a reason for /etc/cron.d/, it’s for local cron jobs, whereas /etc/crontab and /etc/cron.hourly/ and /etc/cron.daily/ are for preinstalled cron jobs, which get deposited by various packages. That’s the convention. And anyway /etc/cron.d/ gives you more flexibility than the others. You can specify the user in contrast to /etc/crontab which is always root, and you can specify the exact time and repetition (even things like every Sunday, or every two hours) instead of once an hour some minute like /etc/cron.hourly/ and once a day sometime like /etc/cron.daily/.

Also note that the format required in /etc/crontab is without the 6th field (user) as it is always run by root, see above.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The system crontab (/etc/crontab) also takes a username as the sixth
string in a line so it too has the same functionality as /etc/cron.d
though using the directory is probably advised for the other reasons you
mentioned.

man 5 crontab

Good luck.

ken yap wrote:
| ab@novell.com;1844030 Wrote:
|> Well, the command ken yap posted should be put in something like
|> /etc/crontab directly. Your script should go in /etc/cron.hourly and
|> then run properly.
|
| No, there’s a reason for /etc/cron.d/, it’s for local cron jobs,
| whereas /etc/crontab and /etc/cron.hourly/ and /etc/cron.daily/ are for
| preinstalled cron jobs, which get deposited by various packages. That’s
| the convention. And anyway /etc/cron.d/ gives you more flexibility than
| the others. You can specify the user in contrast to /etc/crontab which
| is always root, and you can specify the exact time and repetition (even
| things like every Sunday, or every two hours) instead of once an hour
| some minute like /etc/cron.hourly/ and once a day sometime like
| /etc/cron.daily/.
|
| Also note that the format required in /etc/crontab is without the 6th
| field (user) as it is always run by root, see above.
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIhtpv3s42bA80+9kRAn59AKCIjNDFyFWvffFAXmpFvG+d31auwgCgiGHG
s3aAk/KtzW6DPa5qG283GJQ=
=A6mP
-----END PGP SIGNATURE-----

You’re right, I stand corrected. I was thinking of user crontabs, edited with crontab -e.

ab@novell.com wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Show the cron entry in its entirety. Also does this work when run
> manually? Do you have any other NTP clients running because, if so,
> you’ll want to add a ‘-u’ option into the ntpdate command.
>
> Good luck.
>
>
>
>
>
> BiLL TuEr wrote:
> | hi,
> |
> | i have created a script “datetime”:
> |
> | #/bin/sh
> | ntpdate de.pool.ntp.org
> |
> | and put it in /etc/cron.hourly but it is not working. seems like it has
> | never run.
> |
> | any ideas what i can do to?
> |
> | BiLL
> |
> |
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFIhs4Q3s42bA80+9kRAhrkAJ4/jKI0yMaP9Q4wmoFdIWFqXE0uqwCfXEKV
> eglenZ+6/+feUHvlpBzd9nA=
> =7Faw
> -----END PGP SIGNATURE-----

You’re missing ‘!’ on the first line.

#!/bin/sh

also, make sure script is executable.

chmod +x datetime


L R Nix
lornix@lornix.com

i have now created a script called datetime:

14 * * * * root ntpdate -s -u de.pool.ntp.org

and have restarted cron, but it was not executed.
any ideas?

greetings

Hi
Unless you specify the environment cron doesn’t know where applications
are. Add the full path to ntpdate;


/usr/sbin/ntpdate


Cheers Malcolm °¿° (Linux Counter #276890)
SLED 10 SP2 i586 Kernel 2.6.16.60-0.25-default
up 7:52, 1 user, load average: 0.09, 0.28, 0.71
GPU GeForce Go 6600 TE/6200 TE Version: 173.14.09

no way. im gonna crazy. every our when i check time it has a difference of 15 minuten. after 2 hours 30 minutes and so on. in messages is no entry that shows my script has run. ntp is synchronising but wrong!

oh man.

greetins

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Care to post what you have in various files currently and what happens
when you run your script (or whatever you are running now) manually from
the command line?

Good luck.

BiLL TuEr wrote:
| no way. im gonna crazy. every our when i check time it has a difference
| of 15 minuten. after 2 hours 30 minutes and so on. in messages is no
| entry that shows my script has run. ntp is synchronising but wrong!
|
| oh man.
|
| greetins
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIj3pw3s42bA80+9kRAsP1AJ4k4WBP2p8fKU9O/UhLRvR7VDD06gCggY7G
WwygMg7PG8v7z0W/E29DZcE=
=p1un
-----END PGP SIGNATURE-----

for those of us observing this thread; it seems BiLL_TuEr is keen his computer reflect accurately local time; early in the thread, ab@novell.com did ask “Any reason you don’t use the NTP client built into SUSE?” and we didn’t seem to get an answer; in NTP configuration in YaST, one can select various sources;

would that not be an acceptable way to tell the time?

hi all,

ok a löittle mor detailed:

  • i have ntp running which was configured by yast. i added one time-server like tick.fh-augsburg.de and checked that ntp starts on boot automaticly. but this ntp seems to synchronize wrong :frowning:
 (1000); set clock manually to the correct UTC time.
29 Jul 16:20:08 ntpd[18127]: synchronized to 192.53.103.108, stratum 1
29 Jul 16:20:08 ntpd[18127]: time slew -0.020147 s
29 Jul 16:20:09 ntpd[18153]: Deleting interface #2 lo, ::1#123, interface stats: received=0, sent=0, dropped=0, active_time=1 secs
29 Jul 16:20:09 ntpd[18153]: Deleting interface #3 eth0, fe80::20c:29ff:feef:7984#123, interface stats: received=0, sent=0, dropped=0, active_time=1 secs
29 Jul 16:20:24 ntpd[18153]: ntpd exiting on signal 15
29 Jul 16:20:32 ntpd[18252]: synchronized to 141.82.49.100, stratum 2
29 Jul 16:20:32 ntpd[18252]: time slew -0.006328 s
29 Jul 16:20:33 ntpd[18266]: Deleting interface #2 lo, ::1#123, interface stats: received=0, sent=0, dropped=0, active_time=1 secs
29 Jul 16:20:33 ntpd[18266]: Deleting interface #3 eth0, fe80::20c:29ff:feef:7984#123, interface stats: received=0, sent=0, dropped=0, active_time=1 secs
29 Jul 16:23:44 ntpd[18266]: synchronized to LOCAL(0), stratum 10
29 Jul 16:23:44 ntpd[18266]: kernel time sync status change 0001
29 Jul 16:24:48 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
29 Jul 17:00:17 ntpd[18266]: synchronized to LOCAL(0), stratum 10
29 Jul 17:38:35 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
29 Jul 17:55:39 ntpd[18266]: synchronized to LOCAL(0), stratum 10
29 Jul 19:00:57 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
29 Jul 20:29:53 ntpd[18266]: synchronized to LOCAL(0), stratum 10
29 Jul 20:45:59 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
29 Jul 21:13:13 ntpd[18266]: time reset +609.176389 s
29 Jul 21:16:33 ntpd[18266]: synchronized to LOCAL(0), stratum 10
29 Jul 21:29:24 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
29 Jul 21:56:42 ntpd[18266]: time reset +609.216049 s
29 Jul 22:00:59 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
29 Jul 23:24:53 ntpd[18266]: synchronized to LOCAL(0), stratum 10
29 Jul 23:46:22 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
30 Jul 00:06:55 ntpd[18266]: time correction of 1218 seconds exceeds sanity limit (1000); set clock manually to the correct UTC time.
nagios:~ #

because of that i decided to use a cron script too. it is located in /etc/cron.d/timedate. this is the script:

nagios:~ # cat /etc/cron.d/timedate
#!/bin/sh

15 * * * * root /usr/sbin/ntpdate -u de.pool.ntp.org

when i try to use script manualy i get an error that the command 15 is not found.

i would like to use only ntp daemon but as i said, it synchronizes wrong! on my other “slave” machine ntp works fine and correct but i didnt know a difference between those two machines.

BiLL

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It sounds like you have a time drift problem. You can see several polls
of NTP work properly but eventually your computer somehow gets off by
|1000 seconds which means NTP (the client) will declare the source as
“insane” and not synchronize from it for safety. Is this a VM? If so
there are known time issues, at least in VMware, but probably with any
virtualization technology because of how time works inside a computer.

Your script is wrong. You have one of two options. EITHER create a
line in /etc/crontab like the one you have in your script OR modify your
current script and make it a valid script. You already know it doesn’t
work because of the error:

15 * * * * root /usr/sbin/ntpdate -u de.pool.ntp.org
when i try to use script manualy i get an error that the command 15 is

It’s telling ‘15’ is not a command, which it is not. You are trying to
put a cron configuration inside a script that will be called by
something (command line, cron, etc.) and as a result bash tells you the
command you have in there is wrong. Trim that entire script back to
just the ‘ntpdate’ command and its parameters (lose ‘15 * * * * root’)
and try running the script again. It should work properly and SLAM the
time immediately to the present. If it does not, troubleshoot the
script. Once all of that is working cron may have a chance to run it
properly.

Again your other option is to put the entire cron configuration line you
currently have in your script into something like /etc/crontab, or in
the root user’s individual crontab but then without ‘root’ in the
configuration.

Good luck.

BiLL TuEr wrote:
| hi all,
|
| ok a löittle mor detailed:
|
| - i have ntp running which was configured by yast. i added one
| time-server like tick.fh-augsburg.de and checked that ntp starts on
| boot automaticly. but this ntp seems to synchronize wrong :frowning:
|
|

Code:
(1000); set clock manually to the correct UTC time.
29 Jul 16:20:08 ntpd[18127]: synchronized to 192.53.103.108, stratum 1
29 Jul 16:20:08 ntpd[18127]: time slew -0.020147 s
29 Jul 16:20:09 ntpd[18153]: Deleting interface #2 lo, ::1#123,

interface stats: received=0, sent=0, dropped=0, active_time=1 secs
| 29 Jul 16:20:09 ntpd[18153]: Deleting interface #3 eth0,
fe80::20c:29ff:feef:7984#123, interface stats: received=0, sent=0,
dropped=0, active_time=1 secs
| 29 Jul 16:20:24 ntpd[18153]: ntpd exiting on signal 15
| 29 Jul 16:20:32 ntpd[18252]: synchronized to 141.82.49.100, stratum 2
| 29 Jul 16:20:32 ntpd[18252]: time slew -0.006328 s
| 29 Jul 16:20:33 ntpd[18266]: Deleting interface #2 lo, ::1#123,
interface stats: received=0, sent=0, dropped=0, active_time=1 secs
| 29 Jul 16:20:33 ntpd[18266]: Deleting interface #3 eth0,
fe80::20c:29ff:feef:7984#123, interface stats: received=0, sent=0,
dropped=0, active_time=1 secs
| 29 Jul 16:23:44 ntpd[18266]: synchronized to LOCAL(0), stratum 10
| 29 Jul 16:23:44 ntpd[18266]: kernel time sync status change 0001
| 29 Jul 16:24:48 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
| 29 Jul 17:00:17 ntpd[18266]: synchronized to LOCAL(0), stratum 10
| 29 Jul 17:38:35 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
| 29 Jul 17:55:39 ntpd[18266]: synchronized to LOCAL(0), stratum 10
| 29 Jul 19:00:57 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
| 29 Jul 20:29:53 ntpd[18266]: synchronized to LOCAL(0), stratum 10
| 29 Jul 20:45:59 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
| 29 Jul 21:13:13 ntpd[18266]: time reset +609.176389 s
| 29 Jul 21:16:33 ntpd[18266]: synchronized to LOCAL(0), stratum 10
| 29 Jul 21:29:24 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
| 29 Jul 21:56:42 ntpd[18266]: time reset +609.216049 s
| 29 Jul 22:00:59 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
| 29 Jul 23:24:53 ntpd[18266]: synchronized to LOCAL(0), stratum 10
| 29 Jul 23:46:22 ntpd[18266]: synchronized to 141.82.49.100, stratum 2
| 30 Jul 00:06:55 ntpd[18266]: time correction of 1218 seconds exceeds
sanity limit (1000); set clock manually to the correct UTC time.
| nagios:~ #

because of that i decided to use a cron script too. it is located in
/etc/cron.d/timedate. this is the script:
Code:
--------------------
nagios:~ # cat /etc/cron.d/timedate
#!/bin/sh
15 * * * * root /usr/sbin/ntpdate -u de.pool.ntp.org
--------------------
when i try to use script manualy i get an error that the command 15 is
not found.
i would like to use only ntp daemon but as i said, it synchronizes
wrong! on my other “slave” machine ntp works fine and correct but i
didnt know a difference between those two machines.
BiLL

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIkKC03s42bA80+9kRAgtKAJ9t3ecmNdVMve+WE9sE1jqtUXMNXACeKaTK
Rql8TTT3qpV+X/va7dGJrAc=
=7VUH
-----END PGP SIGNATURE-----

when i have trimmed my commandline can i leave the script in /etc/cron.d? or should i put it back to cron.hourly?

and yes it is a vmware server machine.

greetings