1846435 Members
2575 Online
110256 Solutions
New Discussion

NTP Script

 
Sam  Lalonde
Occasional Contributor

NTP Script

I am trying to write a script that will check all of the hosts in my environment to see if any of them have the time out of sync with our NTP time server. In addition, if any hosts are out of sync, I want to generate a message for ITO. Has anyone done (any part of) this sort of thing?

thanks,
sam
9 REPLIES 9
Rita C Workman
Honored Contributor

Re: NTP Script

If you have set up NTP correctly than any slight differences would be corrected using the driftfile, thus keeping time in sync.

Rgrds,
Rita


Shannon Petry
Honored Contributor

Re: NTP Script

Kind of along the lines Rita mentioned, why the redundancy? NTP is supposed to keep time balanced, but with some tolerance for drift.

I would think it more pertinant to have local scripts to ensure that ntp client services are running and restart if necessary.

Just my 2 cents though.

Regards,
Shannon
Microsoft. When do you want a virus today?
Marco Santerre
Honored Contributor

Re: NTP Script

As Rita mentionned, any time difference should be corrected if you have set up your NTP with a driftfile. You can look in /etc/rc.config.d/netdaemons to set up your NTP time sync and in /etc/ntp.conf to set up your drift file.

As far as ITO is concerned, I am not exactly sure how our ITO is set up exactly, but it does pick up NTP problems automatically. So if it ever loses connection with our main time server, it reports a message. And I know that I didn't set up anything within NTP to do that, so it must be ITO.
Cooperation is doing with a smile what you have to do anyhow.
John Bolene
Honored Contributor

Re: NTP Script

fairly easy

either have a list of machines in a loop on the ntp server or on each machine

telnet ntp-server daytime;date

and compare the results
It is always a good day when you are launching rockets! http://tripolioklahoma.org, Mostly Missiles http://mostlymissiles.com
Bob_Vance
Esteemed Contributor

Re: NTP Script

Either:
. schedule on each system
or
. have a list of machines and do remotely

the following:

/usr/sbin/ntpq -p

This shows whether the system is in sync with its servers and/or peers.

An '*' in the state column (1st character) says "synced".

bv
"The lyf so short, the craft so long to lerne." - Chaucer
Bob_Vance
Esteemed Contributor

Re: NTP Script

BTW, another little trick that I often use is:

(on one command line)

golf ## remsh ntp-server -l rb date ; date
Thu Feb 6 08:22:52 EST 2003
Thu Feb 6 08:22:52 EST 2003

If the two times come back the same or within one second, then you're fairly (but only fairly ;>) sure that things are working, at least to within the network delay.

bv
"The lyf so short, the craft so long to lerne." - Chaucer
Brian Kinney
Frequent Advisor

Re: NTP Script

I am writing one in Perl myself - but it is not completed. I will post it when it is complete.

I am using the remote capabilities of ntp to provide me the answers.

ntpq -p

The big bonus is that you don't need rsh, ssh or other rights to run your test!


You'll either get back:
no answer,

Permission denied

or NTP data and stats.

If you get correct data, then parse for an entry starting with an asterisk. If there is one, you are synchronized to some NTP host somewhere. Of course, you could filter to known hosts, confirming you are properly synchronizing to the right places.

Since I am a Perl newbie, this could take a bit of time. (I opted to use perl to force myself to learn it.)

kinney@crd.ge.com


"Any sufficiently advanced technology can be indistinguishable from magic" Arthur C. Clarke. My corollary - "Any advanced technology can be crushed with a sufficently large enough rock."
Bill Hassell
Honored Contributor

Re: NTP Script

NTP on each client will log problems in syslog.log, so I would setup a rule for ITO to look at syslog.log rather than creating a separate process. NTP is extremely sophisticated (much more so than remsh/date and will keep clients within 128ms accuracy or better. Adjustments are very slow and never miss a second, and the only problem with NTP is a naive sysadmin that runs the date command to set the timne-of-day to some wall clock. I would wrapper the date command for root so any attempt to change the date creates a warning and logs (emails) the attempt. Database corruption, especially between different machines, is a consequence of changing the time manually.


Bill Hassell, sysadmin
James Odak
Valued Contributor

Re: NTP Script

this is what i use


### Date check script, run only in cron
SHOUR=`/usr/bin/date +%H`
SMIN=`/usr/bin/date +%M`



for x in `cat /fileofservers`
do
CHOUR=`remsh $x "/usr/bin/date +%H"`
CMIN=`remsh $x "/usr/bin/date +%M"`

if [[ $SHOUR -ne $CHOUR ]]
then
opcmsg severity=major application=time object=hours msg_t="The time value in hours is incorrect" node=$x

fi

if [[ $SMIN -ne $CMIN ]]
then
opcmsg severity=minor application=time object=hours msg_t="The time value in minutes is incorrect" node=$x

fi

done




set this to run in your cron so it begins at the turn of a new min, as long as you do not have 30 or more servers it should never run more then a minute ... (not withstanding over utilization of the processors)

configure ITO/OPO to handle this acrodingly