Skip to content

Instantly share code, notes, and snippets.

@mostlygeek
Created February 24, 2011 18:50
Show Gist options
  • Save mostlygeek/842650 to your computer and use it in GitHub Desktop.
Save mostlygeek/842650 to your computer and use it in GitHub Desktop.
Runs ntpdate if the clock is off by more than 10 seconds. Useful for VMhosts
#!/bin/sh
DIFF=`ntpdate -q pool.ntp.org | awk '/offset ([-0-9\.]+) sec/ {i=int($10); print (i >= 0) ? i : 0 - i}'`
# set the date if the difference is > 10 seconds
if [ $DIFF -gt 10 ];
then
echo -n "Time off by $DIFF seconds. Setting date ..."
sudo ntpdate pool.ntp.org
echo "one";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment