Skip to content

Instantly share code, notes, and snippets.

@tcotav
Created August 25, 2013 22:06
Show Gist options
  • Save tcotav/6336598 to your computer and use it in GitHub Desktop.
Save tcotav/6336598 to your computer and use it in GitHub Desktop.
python ping -- put into cron, every minute
#!/usr/bin/env python
import subprocess
import datetime
import time
from os.path import expanduser
home = expanduser("~")
today=datetime.date.today()
host = "www.google.com"
SLEEPTIME=15
count = 0
f=open("%s/bin/pingtimes-%s.log" % (home,today), "a")
while count < 3:
dt= datetime.datetime.now()
ping = subprocess.Popen(
["ping", "-c", "1", host],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE
)
out, error = ping.communicate()
lines=out.split("\n")
data=lines[1].split(" ")
key,val= data[6].split("=")
f.write("%s,%s\n" % (dt,val))
count+=1
time.sleep(SLEEPTIME)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment