# # cron.py # # List the logged (executed) cron jobs and their commands # TODO: also output a list of scheduled (future) jobs import re from ..formatting import * from ..util import readlog, resolve from .. import config import logging logger = logging.getLogger(__name__) def parse_log(): logger.debug("Starting cron section") section = Section("cron") matches = re.findall('.*CMD\s*\(\s*(?!.*cd)(.*)\)', readlog(config.prefs['logs']['cron'])) num = sum(1 for line in matches) commands = [] for match in matches: commands.append(str(match)) # commands.append([str(match)for match in matches]) #logger.debug("found cron command " + str(commands)) logger.info("Found " + str(num) + " cron jobs") subtitle = str(num) + " cron jobs run" section.add_data(Data(subtitle)) if (len(matches) > 0): commands = ("`{0}`".format(x) for x in commands) commands = orderbyfreq(list(commands)) commands = truncl(commands, config.prefs['maxcmd']) section.add_data(Data("top cron commands", commands)) logger.info("Finished cron section") return section