Sets system time based on what is reported by google.com. Useful for cases where it is not possible to use the standard ntpdate
command. For eample, if a Linux machine is on a network which is only able to reach the internet through an HTTP proxy.
Inspired by ryenus' answer @ https://superuser.com/a/807326/72342
# Download latest set_system_clock_from_google.sh script.
curl -sS --remote-name-all $( \
curl -sS https://api.github.com/gists/60c8a4e22431c4271200cab68186deb7 \
| jq -r '.files[].raw_url' \
| grep -v '\/\._' \
)
# Set permissions and move to local sbin.
chmod a+x set_system_clock_from_google.sh
sudo chown root:root set_system_clock_from_google.sh
sudo mv set_system_clock_from_google.sh /usr/local/sbin/
Here is a command to install a cronjob which syncs the system clock at the top of every hour:
(sudo crontab -l 2>/dev/null; echo '1 * * * * /usr/local/sbin/set_system_clock_from_google.sh') \
| sudo crontab -
List all root cronjobs and verify the job has been added:
sudo crontab -l
1 * * * * /usr/local/sbin/set_system_clock_from_google.sh
Verbose output is available when the -v
flag is passed.
/usr/local/sbin/set_system_clock_from_google.sh -v
Great!
This script indeed solved my problem of some servers.