Shell脚本未通过crontab运行,但手动运行正常

Shell脚本未通过crontab运行,但手动运行正常

问题描述:

我有一个脚本来检查pptp vpn是否正在运行,如果没有运行,它会重新连接pptp vpn,当我手动运行脚本时,它会执行得很好,当我设置了cron作业时,它不会运行

I have a script that checks if pptp vpn is running , and if not it reconnect the pptp vpn , when i run the script manually it execute fine , when i do set a cron job , is not running

* * * * * /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

最后,我找到了解决方法...而不是使用

finally i found a solution ... instead of entering the cronjob with

crontab -e

我需要直接编辑crontab文件

i needed to edit the crontab file directly

nano /etc/crontab

添加例如像

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

,现在很好!

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

Thank you all for your help ... hope my solution will help other people as well.