python 查看Linux cront
#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
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341