#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+= ' <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>
Print HTML
Python View Linux crontab list