Files
WPIQ/wo/core/cron.py

35 lines
1.3 KiB
Python
Raw Normal View History

2018-11-13 21:55:59 +01:00
from wo.core.shellexec import WOShellExec
from wo.core.logging import Log
"""
Set CRON on LINUX system.
"""
2019-04-25 01:25:13 +02:00
2018-11-13 21:55:59 +01:00
class WOCron():
2019-04-29 02:06:32 +02:00
def setcron_weekly(self, cmd, comment='Cron set by WordOps', user='root',
min=0, hour=12):
if not WOShellExec.cmd_exec(self, "crontab -l "
"| grep -q \'{0}\'".format(cmd)):
2018-11-13 21:55:59 +01:00
WOShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l "
2019-04-25 01:25:13 +02:00
"2> /dev/null | {{ cat; echo -e"
" \\\""
"\\n0 0 * * 0 "
"{0}".format(cmd) +
" # {0}".format(comment) +
"\\\"; } | crontab -\"")
2018-11-13 21:55:59 +01:00
Log.debug(self, "Cron set")
2019-04-25 01:25:13 +02:00
def remove_cron(self, cmd):
2019-04-29 02:06:32 +02:00
if WOShellExec.cmd_exec(self, "crontab -l "
"| grep -q \'{0}\'".format(cmd)):
2018-11-13 21:55:59 +01:00
if not WOShellExec.cmd_exec(self, "/bin/bash -c "
2019-04-25 01:25:13 +02:00
"\"crontab "
"-l | sed '/{0}/d'"
"| crontab -\""
.format(cmd)):
Log.error(self, "Failed to remove crontab entry", False)
2018-11-13 21:55:59 +01:00
else:
Log.debug(self, "Cron not found")