I have this script, had some issues with it before, but anyway, now it works properly.
import croniter
import datetime
import re
now = datetime.datetime.now()
def main():
f = open("/etc/crontab","r")
f1 = f.readlines()
for x in f1:
if not re.match('^[0-9*]', x):
continue
a = re.split(r'\s+', x)
cron = croniter.croniter(' '.join(a[:5]), now)
cron.get_next(datetime.datetime)
print(x)
if __name__ == "__main__":
main()
This prints the content of my crontab
file like this:
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
It's okay, but I'm using croniter
for a reason, I could achieve this result by simply doing:
def main():
f = open("/etc/crontab","r")
f1 = f.readlines()
for x in f1:
print(x)
if __name__ == "__main__":
main()
What I'm looking for, is to print this in a human-like way, something like this answer
Any ideas?