Skip to content

Instantly share code, notes, and snippets.

@miawgogo
Created July 10, 2015 14:15
Show Gist options
  • Save miawgogo/c84964e57fc04f0abe0b to your computer and use it in GitHub Desktop.
Save miawgogo/c84964e57fc04f0abe0b to your computer and use it in GitHub Desktop.
python uptime log
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