pptp (pon) fails when called via cron (debian)

Solution 1:

The error message you posted sort of points to a bug in pppd, however the situation you described "works from shell but not from cron" is usually related to path issues.

since it can't hurt, can you try adding this to the top of your crontab?

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

edit: one workaround you could use, is if it always works from the shell, have another short script that does a

while true;do vpnup.sh;sleep 1m;done >> log

then you can just start that in screen with something like

screen -S vpn -d -m thatscript

Solution 2:

Thanks this worked for me! My config now looks like this...

#!/bin/bash
result=`ifconfig | grep ppp0 | wc -l`
if [[ $result  != "1" ]]; then
pon hma
sleep 10
route add -net 0.0.0.0 ppp0 #Routes all traffic on the server through VPN (useful)
fi

And my cron...

# m h  dom mon dow   command
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * * /home/foo/restart_vpn.sh