【发布时间】:2017-08-10 23:16:33
【问题描述】:
我需要一个脚本来运行一个停止 nginx 的 bash 脚本,然后启动 nginx
crontab 看起来像这样
5 10 * * 0 sh ~/runnow/script.sh
我编辑了以 root 身份登录的 crontab。
脚本运行良好,但是 nginx 的停止和启动行给出了错误服务未找到。
echo "Stopping Nginx"
service nginx-sp stop
给了
Stopping Nginx
/root/run/script.sh: 2: /root/run/script.sh: service: not found
如果我手动运行以 root 身份登录的脚本,它运行良好。 我的想法是 crontab 没有以 root 身份运行,但是如果您在使用 crontab -e 以 root 身份登录时退出了您的 crontab,那么它应该以 root 身份运行。一定是因为我使用~/run/script.sh 来运行脚本,而真正的路径是/root/run/script.sh
所以……我迷路了……
【问题讨论】:
-
我建议将
service替换为/path/to/service。