import os import re class CmdUpdate: def __init__(self, config): self.config = config def execute(self): print("Updating...") stream = os.popen("crontab -l") crontab = stream.read() result = crontab begin = re.search("\s*#\s*BEGIN\(ALERTS\).*", crontab) if begin: fragment = "" with open(self.config["CronFragment"]) as file: fragment = file.read() result = crontab[:begin.span()[1]] + "\n" result += fragment end = re.search("\s*#\s*END\(ALERTS\).*", crontab) if end: result += crontab[end.span()[0]:] print(result)