Last active
September 14, 2017 17:16
-
-
Save rvido/40767302627323bde820ee735d359140 to your computer and use it in GitHub Desktop.
Time synchonization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This is a simple shell script to synchonize a computer's time with a webserver | |
# as reference time source. | |
# Make sure command 'curl' is installed or use 'wget' instead | |
# Use any server URL such as www.yahoo.com, www.ebay.com, www.ibm.com, | |
# www.microsoft.com, etc. | |
URL="http://www.google.com" | |
CURL=$(which curl) | |
get_date_from_server() | |
{ | |
${CURL} -I ${URL} 2>&1 /dev/null | grep -E '^[[:space:]]*[dD]ate:' | head -n1 | \ | |
sed -e 's/^[[:space:]]*[dD]ate:[[:space:]]*//' -e 's/,//' | \ | |
awk '{print $1, $3, $2, $5 , "GMT", $4}' | |
} | |
if [ "${CURL}" == "" ]; then | |
echo "Install 'curl' or modify me to use wget" | |
exit | |
fi | |
sudo date -s "$(get_date_from_server)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment