Created
February 13, 2014 13:22
-
-
Save ruairif/8974941 to your computer and use it in GitHub Desktop.
Is NTP blocked on your network? Have you no access to a GPS? Does your computer complain about SSL certs? Then you might just need a quick and dirty time setting script.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
'''\ | |
Instructions: | |
Make this script Executable:: | |
chmod +x set_date.py | |
Place this script in /opt:: | |
cp set_date.py /opt/ | |
To set this script to run every 5 minutes as a cron job as root:: | |
crontab -e | |
Then add the following line:: | |
*/5 * * * * /opt/set_date.py | |
''' | |
import sys | |
from subprocess import call | |
PY2 = sys.version_info[0] == 2 | |
if PY2: | |
from urllib2 import urlopen | |
else: | |
from urllib.request import urlopen | |
def set_date(time): | |
command = ['date', '--set', time] | |
call(command) | |
def get_date(url='http://google.com'): | |
resp = urlopen(url) | |
return resp.headers['date'] | |
if __name__ == '__main__': | |
set_date(get_date()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment