Skip to content

Instantly share code, notes, and snippets.

@jeremykendall
Created October 6, 2014 15:00
Show Gist options
  • Save jeremykendall/79aacd0eecf23d2276e8 to your computer and use it in GitHub Desktop.
Save jeremykendall/79aacd0eecf23d2276e8 to your computer and use it in GitHub Desktop.
Forcing a clock update using NTP: bash script edition
#!/bin/bash
# Forces an ntp update
#
# Based on SO user Martin Schröder's answer to "How to force a clock update
# using ntp?": http://askubuntu.com/a/256004/41943
# Fail fast (set -e will bail at first error)
set -e
if [ "$EUID" -ne 0 ]; then
echo "ERROR: '$0' must be as root."
exit 1
fi
service ntp stop
echo "Running 'ntpd -gq'"
ntpd -gq
service ntp start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment