Thursday, November 6, 2014

Linux -- a handy bash script for time syncronization, ntpdate

This one is a handy script for time syncronization.. It basically does a ntpdate..
If you dont want to use ntp daemon or do not have a ntp daemon, put this script on crontab and sync your time accordingly.

ntpdate sets the local date and time by polling the Network Time Protocol (NTP) server(s) given as the server arguments to determine 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.

#!/bin/sh
NTPDATE=/usr/sbin/ntpdate
SERVER="YOUR NTP SERVERS IP ADDRESS HERE"

if ! test -t 0; then
  MYRAND=$RANDOM
  MYRAND=${MYRAND:=$$}

  if [ $MYRAND -gt 9 ]; then
    sleep `echo $MYRAND | sed 's/.*\(..\)$/\1/' | sed 's/^0//'`
  fi
fi

$NTPDATE -su $SERVER
if [ -f /sbin/hwclock ]; then
  /sbin/hwclock --systohc
fi

No comments :

Post a Comment

If you will ask a question, please don't comment here..

For your questions, please create an issue into my forum.

Forum Link: http://ermanarslan.blogspot.com.tr/p/forum.html

Register and create an issue in the related category.
I will support you from there.