Sponsored Content
Full Discussion: Script to detect time drift
Operating Systems HP-UX Script to detect time drift Post 303017325 by rbatte1 on Monday 14th of May 2018 07:32:47 AM
Old 05-14-2018
You would have to do this on the client side. If you have a problem with your NTP time server, then treat that as the client and get it to align to another trusted clock, be that a radio-clock or internet address.

You can also use ntpdate -d refer-server to get a time difference from the reference server (which must be offering the NTP service, of course)

if the clock drift is too far, then you would need to step the clock on the local server to match something like this:-
  • Check the offset with - ntpdate -d ref-server
  • Stop the local NTP service in the normal way
  • Step the clock into sync - ntpdate ref-server
  • Start the local service in the normal way
  • Check the offset with - ntpdate -d ref-server

You should see debug information when you use the -d flag and the last line gives you the agreed offset from the reference server or servers (just a space separated list)


If you can't have the NTP client running all the time because your application doesn't like the clock going backwards even by tiny fractions of a second, you would probably need to schedule and idle minute to step the clock each day. You can run ntpdate -d ref-server at any time and just use the last line to show you the current offset from the trusted clock.



I hope that this helps,
Robin
 

9 More Discussions You Might Find Interesting

1. 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

2. 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) "www.google.com"... (1 Reply)
Discussion started by: ROFL
1 Replies

3. 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: www.google.com www.facebook.com www.google.com the output should be: www.google.com x2... (2 Replies)
Discussion started by: ROFL
2 Replies

4. 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/script.sh Here the normal execution starts every 5 minutes Example #1 runs by... (16 Replies)
Discussion started by: Lord Spectre
16 Replies

5. Shell Programming and Scripting

How to detect Hanged process in shell script?

I have to check daily 20 processes each day. The names are like Network1 Network2 Network3 ....... Network20. There is built in utility for doing this. Following is the command to check a single network process. check_process_status 1 If we want to check the status of Network2 then the... (6 Replies)
Discussion started by: Nakul_sh
6 Replies

6. 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

7. 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

8. 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

9. 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:///path_to_myscript.sh url1 url2 url3 myscript.sh: #!/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
NTPDATE(8)						    BSD System Manager's Manual 						NTPDATE(8)

NAME
ntpdate -- set the date and time via NTP SYNOPSIS
ntpdate [-bBdoqsuv] [-a key] [-e authdelay] [-k keyfile] [-o version] [-p samples] [-t timeout] server ... DESCRIPTION
Note: The functionality of this program is now available in the ntpd(8) program. See the -q command line option in the ntpd(8) page. After a suitable period of mourning, the ntpdate utility is to be retired from this distribution. The ntpdate utility sets the local date and time by polling the Network Time Protocol (NTP) server(s) given as the server arguments to deter- mine the correct time. It must be run as root on the local host. A number of samples are obtained from each of the servers specified and a subset of the NTP clock filter and selection algorithms are applied to select the best of these. Note that the accuracy and reliability of ntpdate depends on the number of servers, the number of polls each time it is run and the interval between runs. The following options are available: -a key Enable the authentication function and specify the key identifier to be used for authentication as the argument key. The keys and key identifiers must match in both the client and server key files. The default is to disable the authentication function. -B Force the time to always be slewed using the adjtime(2) system call, even if the measured offset is greater than +-128 ms. The default is to step the time using settimeofday(2) if the offset is greater than +-128 ms. Note that, if the offset is much greater than +-128 ms in this case, it can take a long time (hours) to slew the clock to the correct value. During this time, the host should not be used to synchronize clients. -b Force the time to be stepped using the settimeofday(2) system call, rather than slewed (default) using the adjtime(2) system call. This option should be used when called from a startup file at boot time. -d Enable the debugging mode, in which ntpdate will go through all the steps, but not adjust the local clock. Information useful for general debugging will also be printed. -e authdelay Specify the processing delay to perform an authentication function as the value authdelay, in seconds and fraction (see ntpd(8) for details). This number is usually small enough to be negligible for most purposes, though specifying a value may improve timekeeping on very slow CPU's. -k keyfile Specify the path for the authentication key file as the string keyfile. The default is /etc/ntp.keys. This file should be in the format described in ntpd(8). -o version Specify the NTP version for outgoint packets as the integer version, which can be 1 or 2. The default is 3. This allows ntpdate to be used with older NTP versions. -p samples Specify the number of samples to be acquired from each server as the integer samples, with values from 1 to 8 inclusive. The default is 4. -q Query only - don't set the clock. -s Divert logging output from the standard output (default) to the system syslog(3) facility. This is designed primarily for conve- nience of cron(8) scripts. -t timeout Specify the maximum time waiting for a server response as the value timeout, in seconds and fraction. The value is rounded to a mul- tiple of 0.2 seconds. The default is 1 second, a value suitable for polling across a LAN. -u Direct ntpdate to use an unprivileged port for outgoing packets. This is most useful when behind a firewall that blocks incoming traffic to privileged ports, and you want to synchronise with hosts beyond the firewall. Note that the -d option always uses unpriv- ileged ports. -v Be verbose. This option will cause ntpdate's version identification string to be logged. The ntpdate utility can be run manually as necessary to set the host clock, or it can be run from the host startup script to set the clock at boot time. This is useful in some cases to set the clock initially before starting the NTP daemon ntpd(8). It is also possible to run ntpdate from a cron(8) script. However, it is important to note that ntpdate with contrived cron(8) scripts is no substitute for the NTP daemon, which uses sophisticated algorithms to maximize accuracy and reliability while minimizing resource use. Finally, since ntpdate does not discipline the host clock frequency as does ntpd(8), the accuracy using ntpdate is limited. Time adjustments are made by ntpdate in one of two ways. If ntpdate determines the clock is in error more than 0.5 second it will simply step the time by calling the system settimeofday(2) routine. If the error is less than 0.5 seconds, it will slew the time by calling the system adjtime(2) routine. The latter technique is less disruptive and more accurate when the error is small, and works quite well when ntpdate is run by cron(8) every hour or two. The ntpdate utility will decline to set the date if an NTP server daemon (e.g., ntpd(8)) is running on the same host. When running ntpdate on a regular basis from cron(8) as an alternative to running a daemon, doing so once every hour or two will result in precise enough time- keeping to avoid stepping the clock. ntpd(8). FILES
/etc/ntp.keys contains the encryption keys used by ntpdate. SEE ALSO
ntpd(8) BUGS
The slew adjustment is actually 50% larger than the measured offset, since this (it is argued) will tend to keep a badly drifting clock more accurate. This is probably not a good idea and may cause a troubling hunt for some values of the kernel variables kern.clockrate.tick and kern.clockrate.tickadj. BSD
January 6, 2000 BSD
All times are GMT -4. The time now is 08:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy