Python View Linux crontab list

Source: Internet
Author: User
Tags prev

#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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.