Home Man
Search
Today's Posts
Register

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

Tags
drift, hp-ux, ntp

👤 Login to reply

 
Thread Tools Search this Thread
# 15  
Old 06-19-2018
Hi there, sorry to bother you again.

When I had this command "ntpq -c rl" run on the server, this the the output I get.

Code:
associd=0 status=0615 leap_none, sync_ntp, 1 event, clock_sync,
version="ntpd 4.2.6 Revision 6.0 Tue April 14 14:21:22 UTC 2015",
processor=, system="HP-UX/", leap=00, stratum=3, precision=-20,
rootdelay=14.482, rootdisp=44.199, refid=10.101.162.196,
reftime=ded28e5d.90b912dc  Mon, Jun 18 2018 16:02:37.565,
clock=ded2918b.a1b70695  Mon, Jun 18 2018 16:16:11.631, peer=23187,
tc=10, mintc=3, offset=0.182, frequency=20.824, sys_jitter=0.211,
clk_jitter=0.122, clk_wander=0.000

Do we still need to check for "Phase" in the script?
Code:
s/.*phase=-\{0,1\}\([0-9]*\).*/\1/p
t


Last edited by Don Cragun; 06-19-2018 at 11:41 AM.. Reason: Change COLOR tags to CODE tags, add missing CODE tags.
# 16  
Old 06-19-2018
Quote:
Originally Posted by Green_Star
Hi there, sorry to bother you again.

When I had this command "ntpq -c rl" run on the server, this the the output I get.
It seems to me that you might profit in understanding from a bit of theory behind NTP and its workings. Here it goes:

Within a network it is vital to keep the timekeeping of the connected systems in sync. For instance the Kerberos protocol will invalidate any authentication attempt coming from a system which time is off by more than a (very narrow) margin from the ticket server. Alas, timekeeping in computers is done basically by some oscillating circuitry which is quite unreliable over periods longer than a few hours at most. This is where NTP comes in to synchronize the system time(s) throughout the network.

NTP is a client-server protocol and works in a hierarchical manner quite like the DNS protocol. At its root there are so-called stratum-1 servers, which generate the correct time using some specially designed hardware (nowadays usually atomic clocks). Atomic clocks are off about a second every other billion of years, so for every practical purpose they are as exact as it gets.

You will never get into contact with a stratum-1 server anyway. These are not publicly available systems but usually secured and talking only to a very few select clients. These clients form the next layer of the hierarchy and are called stratum-2 servers (now, who'd have guessed that?). They are on one hand clients to the stratum-1 servers, so their time is (almost, save for a margin you won't notice) as exact as them and on the other hand act as servers to the interested public.

That still doesn't mean they are publicly available. In fact a company usually has a contract with a company running a stratum-2 server and accesses with one (or two) client system(s) this service. These one or two systems act themselves as so-called stratum-3 servers giving out their time information to every server on the company network.

Now, how is timekeeping with NTP done: basically a client checks with his assigned server from time to time and if there is a difference in the gotten time information and the current system time the system time is adjusted. It could be adjusted by simply setting it but this would create some problems: suppose the system time is 12:00:00 and a file is written. It would get the time stamp of 12:00:00. Now the NTP process sets the time back 5 seconds becaause it got the new information from its NTP server, so the system time would now be 11:59:55. Suppose a process would now try to find the last file one second later and notice that - from its POV - the file would be from the future. No good!

This is why time is usually adjusted "driftingly": the "seconds" on the affected system will be somewhat shortened or lengthened so that the "subjective" time on the system still passes continuously but eventually synchronises with the NTP servers information. This drifting is logged in the "drift file". Notice that per default the drift file resides in /etc and can get pretty big if the timing circuitry of the underlying hardware is crap. I had a few (AIX) systems in my career having fits because of a full root FS after the drift file in /etc filled it up. I'm not sure for HP-UX, but IIRC they don't like a full root FS any better.

You probably can understand your output now a little better.

I hope this helps.

bakunin
The Following 2 Users Say Thank You to bakunin For This Useful Post:
Green_Star (06-21-2018), rbatte1 (06-22-2018)
# 17  
Old 06-20-2018
Looks like the "ntpq -c rl" changes with every update of the NTP package.
Take the "ntpq -pn" output instead! To be processed like this in the shell script:
Code:
offset=$(
ntpq -pn | awk '/^[*]/ {print $9}'
)

The Following User Says Thank You to MadeInGermany For This Useful Post:
Green_Star (06-22-2018)
# 18  
Old 06-21-2018
Thanks a lot Bakunin. That really helps me understand the background!!!

---------- Post updated at 11:52 AM ---------- Previous update was at 09:57 AM ----------

Quote:
Originally Posted by MadeInGermany
Looks like the "ntpq -c rl" changes with every update of the NTP package.
Take the "ntpq -pn" output instead! To be processed like this in the shell script:
Code:
offset=$(
ntpq -pn | awk '/^[*]/ {print $9}'
)

Just wondering what would be the value of "offset" using "ntpq -pn" if NTP service is down? Will it be 0 or BLANK?
Command "awk" will print the 9th value of the output "ntpq -pn". So just wondering if NTP service is down, and the offset is BLANK, awk will print "disp" value to the output variable instead of BLANK. Thanks for your time.
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 05-10-2018 03:13 PM
A script to detect system type dampio UNIX for Advanced & Expert Users 1 01-24-2018 05:02 AM
Help with detect with regex and move script Simplify Shell Programming and Scripting 7 01-19-2017 09:58 AM
Using grep command to detect presence of script run wtolentino Shell Programming and Scripting 8 04-01-2014 06:53 PM
How to detect key press in cgi shell script? Shuinvy Shell Programming and Scripting 2 12-07-2012 04:06 AM
Detect if script starts from queue Lord Spectre Shell Programming and Scripting 16 08-16-2012 11:09 AM
AWK script to detect webpages from file ROFL Shell Programming and Scripting 2 03-23-2010 08:22 AM
AWK script to detect webpages from file ROFL Shell Programming and Scripting 1 03-22-2010 12:22 PM
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 03:16 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password