Created
August 25, 2013 22:06
-
-
Save tcotav/6336598 to your computer and use it in GitHub Desktop.
python ping -- put into cron, every minute
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 | |
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