From d1ea3ab4e248c3df9e1098dbae2e304ae49b0280 Mon Sep 17 00:00:00 2001 From: Prabuddha Chakraborty Date: Fri, 18 Dec 2015 19:28:05 +0530 Subject: [PATCH] added check_isexist function --- ee/core/cron.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/ee/core/cron.py b/ee/core/cron.py index b9aa5d27..11e106b3 100644 --- a/ee/core/cron.py +++ b/ee/core/cron.py @@ -1,4 +1,5 @@ from crontab import * +from ee.core.shellexec import EEShellExec from ee.core.logging import Log """ @@ -7,10 +8,20 @@ Set CRON on LINUX system. class EECron(): def setcron_daily(self,cmd,comment='Cron set by EasyEngine',user='root',min=0,hour=12): - tab = CronTab(user=user) - cron_job = tab.new(cmd, comment=comment) - cron_job.minute().on(min) - cron_job.hour().on(hour) - #writes to crontab - tab.write() - Log.debug(self, "Cron is set:\n" + tab.render()) + if not self.check_isexist(self,cmd): + tab = CronTab(user=user) + cron_job = tab.new(cmd, comment=comment) + cron_job.minute().on(min) + cron_job.hour().on(hour) + #writes to crontab + tab.write() + Log.debug(self, "Cron is set:\n" + tab.render()) + + #Check if cron already exist + def check_isexist(self,cmd): + + if EEShellExec.cmd_exec(self, "crontab -l | grep -q \'{0}\'".format(cmd)): + Log.debug(self, "Cron already exist") + return True + else: + return False \ No newline at end of file