-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_cron_schedule.py
More file actions
25 lines (19 loc) · 2.11 KB
/
my_cron_schedule.py
File metadata and controls
25 lines (19 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import cron_descriptor as cd
import subprocess as sp
def crontabline2english(line):
words = line.split()
schedule = ' '.join(words[:5])
command = ' '.join(words[5:])
sched_eng = cd.get_description(schedule)
activity = sched_eng + ', ' + command
return activity
# execute a linux command and get the output
lines = sp.check_output('crontab -l', shell=True).decode('utf-8').strip()
# make a list of lines, removing the lines that start with #
lines = [line.strip() for line in lines.split('\n') if not line.startswith('#')]
if lines:
print("My Cron Schedule:")
for line in lines:
print(' * ' + crontabline2english(line))
else:
print("No Cron jobs scheduled")