1#
2# cron.py
3#
4# List the logged (executed) cron jobs and their commands
5# TODO: also output a list of scheduled (future) jobs
6
7import re
8
9from ..formatting import *
10from ..util import readlog, resolve
11from .. import config
12
13import logging
14logger = logging.getLogger(__name__)
15
16def parse_log():
17 logger.debug("Starting cron section")
18 section = Section("cron")
19 matches = re.findall('.*CMD\s*\(\s*(?!.*cd)(.*)\)', readlog(config.prefs['logs']['cron']))
20 num = sum(1 for line in matches)
21 commands = []
22 for match in matches:
23 commands.append(str(match))
24 # commands.append([str(match)for match in matches])
25 #logger.debug("found cron command " + str(commands))
26 logger.info("Found " + str(num) + " cron jobs")
27 jobs_data = Data(str(num) + " cron jobs run")
28 section.append_data(jobs_data)
29
30 if (len(matches) > 0):
31 logger.debug("Analysing cron commands")
32 cmd_data = Data("Top cron commands")
33 cmd_data.items = ("`{0}`".format(x) for x in commands)
34 cmd_data.orderbyfreq()
35 cmd_data.truncl(config.prefs['maxcmd'])
36 section.append_data(cmd_data)
37
38 logger.info("Finished cron section")
39 return section