Unix/Linux Go Back    


HP-UX HP-UX (Hewlett Packard UniX) is Hewlett-Packard's proprietary implementation of the Unix operating system, based on System V.

Script to detect time drift

HP-UX


Tags
drift, ntp

Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 1 Week Ago   -   Original Discussion by Green_Star
Green_Star's Unix or Linux Image
Green_Star Green_Star is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 24 May 2018, 10:01 AM EDT
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Thanks a lot for your response MadeInGermany.

I will try this.

Thanks.
Sponsored Links
    #9  
Old Unix and Linux 1 Week Ago   -   Original Discussion by Green_Star
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 26 May 2018, 5:54 PM EDT
Location: Simplicity
Posts: 4,085
Thanks: 351
Thanked 1,379 Times in 1,243 Posts
The following is even simpler, because sed simply strips a leading - and a trailing .xxx.
This would even run in bash or dash.


Code:
#!/bin/ksh
PATH=/bin:/usr/bin:/usr/sbin:/sbin
offset=$(
ntpq -c rl | sed -n '
s/.*phase=-\{0,1\}\([0-9]*\).*/\1/p
t
s/.*offset=-\{0,1\}\([0-9]*\).*/\1/p
'
)
if [[ -z $offset ]]
then
  echo "no offset, check NTP service with ntpq -pn"
elif [[ $offset -gt 50 ]]
then
  echo "$offset is greater than 50 msec"
fi


Last edited by MadeInGermany; 1 Week Ago at 02:29 PM.. Reason: added check for empty return value
Sponsored Links
    #10  
Old Unix and Linux 1 Week Ago   -   Original Discussion by Green_Star
Green_Star's Unix or Linux Image
Green_Star Green_Star is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 24 May 2018, 10:01 AM EDT
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Hi MadeInGermany,

Quick question for my knowledge purposes.
If NTP is scheduled to run every 10 minutes on the server, do you think the clocks get synchronised?
Will there be an explicit need to check for the time drifts? Can the time drift situation occur at all?

Thank you.
    #11  
Old Unix and Linux 1 Week Ago   -   Original Discussion by Green_Star
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 26 May 2018, 5:54 PM EDT
Location: Simplicity
Posts: 4,085
Thanks: 351
Thanked 1,379 Times in 1,243 Posts
This ntpq is a measurement.
If you trust your NTP setup then you do not need a measurement.

BTW I just have changed my last post, added another check for the case that NTP service does not work (somebody stopped it, all time peers are unreachable, ...).

With HP-UX 11.23 I remember a strangeness: ntpq reported sudden time jumps and the monitoring got occasional alerts.
No such issues on AIX, Solaris, Linux.

driftfile is not relevant. This is the drift between the hardware clock and the NTP servers., that predicts the real drift in case the time peers would not be reachable. Effectively it only causes a faster time sync after a startup of the NTP service. One can run NTP without a driftfile.

Last edited by MadeInGermany; 1 Week Ago at 02:39 PM..
The Following User Says Thank You to MadeInGermany For This Useful Post:
Green_Star (1 Week Ago)
Sponsored Links
    #12  
Old Unix and Linux 1 Week Ago   -   Original Discussion by Green_Star
Green_Star's Unix or Linux Image
Green_Star Green_Star is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 24 May 2018, 10:01 AM EDT
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Perfect!!

Thanks a lot for sharing your knowledge - MadeInGermany.
Sponsored Links
    #13  
Old Unix and Linux 3 Days Ago   -   Original Discussion by Green_Star
Green_Star's Unix or Linux Image
Green_Star Green_Star is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 24 May 2018, 10:01 AM EDT
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Hello,

One more question.
Once we detect the offset >+/- 50ms, can we correct the time within the script i.e. get the time in sync ?

Thanks!

Last edited by Green_Star; 3 Days Ago at 11:36 AM..
Sponsored Links
    #14  
Old Unix and Linux 3 Days Ago   -   Original Discussion by Green_Star
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 26 May 2018, 5:54 PM EDT
Location: Simplicity
Posts: 4,085
Thanks: 351
Thanked 1,379 Times in 1,243 Posts
No, this is monitoring. Once monitoring detects an offset you must do a root cause analysis why your sync mechanism has failed.
Your sync mechanism:
ensure there is either ntpd running (needs a correctly configured ntp.conf, check with ntpq -pn) or a cron job with ntpdate.
The Following User Says Thank You to MadeInGermany For This Useful Post:
Green_Star (3 Days Ago)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to detect time drift on server Green_Star UNIX for Beginners Questions & Answers 1 2 Weeks Ago 03:13 PM
A script to detect system type dampio UNIX for Advanced & Expert Users 1 01-24-2018 05:02 AM
Detect if script starts from queue Lord Spectre Shell Programming and Scripting 16 08-16-2012 11:09 AM
how to detect my script is already running rmulchandani UNIX for Dummies Questions & Answers 11 01-26-2009 05:10 PM



All times are GMT -4. The time now is 08:53 PM.