发布时间:2019-09-08 09:13:06编辑:auto阅读(1347)
#encoding:utf-8
#!/usr/local/bin/python
from crontab import CronTab
import sys,re
from croniter import croniter
from datetime import datetime
import socket
import fcntl
import struct
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
if __name__=='__main__':
cron=CronTab(user='user0')
host=get_ip_address('eth0')
HTML='<html><head><title>'+host+'</title></head><body>'
HTML+='<style>th,td{border:solid 1px #eee;}</style>'
HTML+='<table><tr><th>Task</th><th>Prev Time</th><th>Next Time</th></tr>'
for job in cron:
#print job.command
schedule = job.schedule(date_from=datetime.now())
exec_next_time = schedule.get_next()
exec_prev_time= schedule.get_prev()
#print (job.command).replace(r'>/dev/null 2>&1','')+" next exec time:"+str(exec_next_time)+" prev exec time:"+str(exec_prev_time)
task=(job.command).replace(r'>/dev/null 2>&1','')
next=str(exec_next_time)
prev=str(exec_prev_time)
HTML+='<tr><td>%s</td><td>%s</td><td>%s</td></tr>'%(task,prev,next)
HTML+='</table><body></html>'
print HTML
上一篇: Python 字典的特点和常用操作
下一篇: Python socket 模块的使用
47851
46412
37296
34743
29323
25981
24927
19959
19551
18040
5800°
6424°
5939°
5967°
7074°
5921°
5952°
6449°
6410°
7791°