Skip to content

crontab相关问题

查看定时任务日志

bash
tail -f /root/.httpsok/httpsok.log

crontab定时任务不存在

解决方案一

在nginx的docker容器中,如果没有crontab,手动安装一下即可。

bash
apt update && apt install cron -y

安装成功后,需要再次执行 httpsok.sh 一键部署脚本。

解决方案二

更换镜像版本,使用 alpine 镜像。

no nginx in PATH

某些场景下,在crontab中执行脚本,可能会提示 no nginx in PATH

bash
2024-09-11 11:26:01 Please confirm that nginx has been successfully installed on your system


no nginx in PATH, find the nginx

2024-09-12 11:26:01 Can’t detected nginx

2024-09-12 11:26:01 Please confirm that nginx has been successfully installed on your system

解决方案:设置 PATH 环境变量。

bash
# 先执行echo $PATH,打印PATH变量
# /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
bash
# 修改crontab设置PATH环境变量
crontab -e
# 每个用户都不同
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
# 26 11 * * * '/root/.httpsok/httpsok.sh' -m -r >> '/root/.httpsok/httpsok.log' 2>&1
bash
echo PATH=$PATH > /tmp/crontab.txt
crontab -l >> /tmp/crontab.txt
crontab < /tmp/crontab.txt