Files
WPIQ/wo/core/cron.py
VirtuBox 42e856173f Several new features
- cht.sh stack : linux online cheatsheet. Usage : `cheat <command>`. Example for tar : `cheat tar`
- ClamAV anti-virus with weekly cronjob to update signatures database
- Internal function to add daily cronjobs
- Additional comment to detect previous configuration tuning (MariaDB & Redis)
- Domain/Subdomain detection based on public domain suffixes list
- Increase Nginx & MariaDB systemd open_files limits
- Cronjob to update Cloudflare IPs list
2019-08-26 18:05:26 +02:00

49 lines
2.0 KiB
Python

from wo.core.shellexec import WOShellExec
from wo.core.logging import Log
"""
Set CRON on LINUX system.
"""
class WOCron():
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)):
WOShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l "
"2> /dev/null | {{ cat; echo -e"
" \\\""
"\\n0 0 * * 0 "
"{0}".format(cmd) +
" # {0}".format(comment) +
"\\\"; } | crontab -\"")
Log.debug(self, "Cron set")
def setcron_daily(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)):
WOShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l "
"2> /dev/null | {{ cat; echo -e"
" \\\""
"\\n@daily"
"{0}".format(cmd) +
" # {0}".format(comment) +
"\\\"; } | crontab -\"")
Log.debug(self, "Cron set")
def remove_cron(self, cmd):
if WOShellExec.cmd_exec(self, "crontab -l "
"| grep -q \'{0}\'".format(cmd)):
if not WOShellExec.cmd_exec(self, "/bin/bash -c "
"\"crontab "
"-l | sed '/{0}/d'"
"| crontab -\""
.format(cmd)):
Log.error(self, "Failed to remove crontab entry", False)
else:
Log.debug(self, "Cron not found")