Created
July 10, 2015 14:15
-
-
Save miawgogo/c84964e57fc04f0abe0b to your computer and use it in GitHub Desktop.
python uptime log
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
import subprocess, datetime | |
def writestatus(status): | |
f=open("uptime", 'a') | |
if status == True: | |
string="[" + str(datetime.date.today()) + " " + str(datetime.datetime.now().time()) + "] Site google.co.uk is up \n" | |
f.write(string) | |
print string | |
elif status == False: | |
string="[" + str(datetime.date.today()) + " " + str(datetime.datetime.now().time()) + "] Site google.co.uk is down \n" | |
f.write(string) | |
print string | |
f.close | |
ret = subprocess.call("ping -c 1 google.co.uk", shell=True, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT) | |
if ret == 0: | |
writestatus(True) | |
else: | |
writestatus(False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment