1. 程式人生 > >python ping監控

python ping監控

lena api class .info AD div eve bin orm

#!/usr/bin/python
# coding=utf-8
importos,sys,time
importlogging
host=114.114.114.114
logging.basicConfig(level=logging.DEBUG,
    format=%(asctime)-30s%(message)s,
    datefmt=%Y-%m-%d%H:%M:%S,
    filename=host+.log,
    filemode=a)
aping=os.popen(ping+host)
whileTrue:
    logging.info(aping.readline().rstrip())

啟動直接 nohup python filename > /dev/null & 就可以了,kill的時候註意要kill兩個進程,一個python 一個ping

python ping監控