我使用Ubuntu 18.04,并且 我在bash中创建了以下脚本:
resumeFlask.sh
#!/bin/bash
ps aux | grep main.py | grep -v grep > /dev/null
result=$?
if [ "${result}" -eq "0" ] ; then
echo "`date`: server flask service running, everything is fine" >> log
else
echo "`date`: server flask is not running" >> log
cd /home/giup/Desktop/
python main.py &
fi
和 resumeMysql.sh :
#!/bin/bash
systemctl is-active --quiet mysql
result=$?
if [ "${result}" -eq "0" ] ; then
echo "`date`: mysql service running, everything is fine" >> log
else
echo "`date`: mysql is not running" >> log
systemctl restart mysql.service
fi
我为这些文件设置了执行权限。
我想每小时执行一次这些脚本,所以我编辑了文件crontab,在sudo crontab -e
中添加了以下几行:
58 * * * * /bin/sh /home/giuseppe/Script/resumeMysql.sh >/dev/null 2>&1
59 * * * * /bin/sh /home/giuseppe/Script/resumeFlask.sh >/dev/null 2>&1
问题是crontab无法正常工作,我尝试彻底sudo service cron restart
重新启动crontab deamon。