gpt4 book ai didi

bash - Shell 脚本未通过 crontab 运行,但手动运行良好

转载 作者:太空宇宙 更新时间:2023-11-04 12:15:53 26 4
gpt4 key购买 nike

我有一个脚本可以检查 PPTP VPN 正在运行,如果没有,它会重新连接 PPTP VPN。当我手动运行脚本时,它执行得很好,但是当我创建一个 cron 作业时,它没有运行。

* * * * * /bin/bash /var/scripts/vpn-check.sh

这是脚本:

#!/bin/sh
/bin/ping -c3 192.168.17.27 > /tmp/pingreport
result=`grep "0 received" /tmp/pingreport`
truncresult="`echo "$result" | sed 's/^\(.................................\).*$$'`"
if [[ $truncresult == "3 packets transmitted, 0 received" ]]; then
/usr/sbin/pppd call home
fi

最佳答案

最后我找到了一个解决方案......而不是进入cronjob

crontab -e

我需要直接编辑crontab文件

nano /etc/crontab

添加例如类似

*/5 *     * * *   root  /bin/bash /var/scripts/vpn-check.sh

现在好了!

谢谢大家的帮助...希望我的解决方案也能帮助其他人。

关于bash - Shell 脚本未通过 crontab 运行,但手动运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47448450/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com