Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.

Script to detect time drift

Login or Register to Reply

Thread Tools Search this Thread
# 15  
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.

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=,
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?

Last edited by Don Cragun; 06-19-2018 at 12:41 PM.. Reason: Change COLOR tags to CODE tags, add missing CODE tags.
# 16  
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.

These 2 Users Gave Thanks to bakunin For This Post:
# 17  
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:
ntpq -pn | awk '/^[*]/ {print $9}'

This User Gave Thanks to MadeInGermany For This Post:
# 18  
Thanks a lot Bakunin. That really helps me understand the background!!!

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

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:
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 or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to detect url in use in a script?

Hello, I have a small script and it runs from web application in below format: pipe:/// url1 url2 url3 #!/bin/bash count=0 while do count=$((count+1)) exec 3>&1 ((ffmpeg -i $1 ...... -f mpegts pipe:1 2>/dev/null 1>&3 ) 2>&1 | \ while read LINE; do echo... (9 Replies)
Discussion started by: baris35
9 Replies

2. UNIX for Beginners Questions & Answers

Script to detect time drift on server

Hello there, I am not an expert in networking related stuff but I got a requirement to create UNIX script to query our Company's internal time source via NTP for time drift detect and report it when > +/- 50ms. I have been googling a lot but thought to post it in this forum to get a... (1 Reply)
Discussion started by: Green_Star
1 Replies

3. UNIX for Advanced & Expert Users

A script to detect system type

Hi forum, So I am trying to determine the OS type with the following script: #!/usr/bin/sh OStype1=`uname -s` Sunos1=SunOs if then echo "This system is Linux" exit 0 elif then echo "This system is SunOs" exit 0 elif (1 Reply)
Discussion started by: dampio
1 Replies

4. Shell Programming and Scripting

Help with detect with regex and move script

Hi all, I am needing some help with a script that will search for a video file by known extensions and then do a pattern search (I'm guessing via regex) and then based on a match of one type of another move the file to an assigned directory. I would like to do this with either a shell script... (7 Replies)
Discussion started by: Simplify
7 Replies

5. Shell Programming and Scripting

Detect current shell inside a script

I wish to print my current shell which happens to be bash in my script more echo $0 echo `ps -p $$` But instead of printing it prints i.e the name of the script for both the commands. Can you please suggest how to print the current shell i m on inside the... (2 Replies)
Discussion started by: mohtashims
2 Replies

6. Shell Programming and Scripting

Bash script to detect nonpingable hosts

I have a script to detect if a host is pingable or not. The problem is that I would like it to put the nonpingable hosts in one file and the pingable hosts in another. I have come up with this so far: for ip in `cat /tmp/testlist2`; do ping -c 3 $ip >/dev/null && echo "$ip is up" || echo "$ip... (5 Replies)
Discussion started by: newbie2010
5 Replies

7. Shell Programming and Scripting

Detect if script starts from queue

Dear community, what I'm try to do is deny users to run a script without parameters from command bash, but the same script should run without parameters only from crontab. Example runs by crontab:*/5 * * * * /tmp/ Here the normal execution starts every 5 minutes Example #1 runs by... (16 Replies)
Discussion started by: Lord Spectre
16 Replies

8. Shell Programming and Scripting

AWK script to detect webpages from file

Hi guys I'm very new to unix and I have to create an awk script that detects webpage addresses from a file/webpage and outputs how many times each webpage was detected.e.g. if my file was: (Note: The symbol " was added to stop them being created into links) ""... (1 Reply)
Discussion started by: ROFL
1 Replies

9. UNIX for Dummies Questions & Answers

how to detect my script is already running

I have a script which must not be run more than once at any given time. THis script will be scheduled to run every 20 mins as a cron job. In my script can i have logic to say if this script is already running from the previous cron, then exit. How do i go about doing that. If you describe the... (11 Replies)
Discussion started by: rmulchandani
11 Replies

Featured Tech Videos