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
Related videos on Youtube
BuildTheRobots
Updated on September 17, 2022Comments
-
BuildTheRobots almost 2 years
I have a pptp VPN link dialing from my (debian) linux server here, to an ISA2003 server at a remote site.
The internet connection at (both) ends is somewhat dodgy, so I have written a little script to call
pon myvpnlink
if it detects the link has gone down.This script works fine if I run it from the CLI, but if its called via cron then the pon call seems to fail.
I have re-written this in both bash and perl and have the same problem with each. The script is executed, it can tell if the VPN link is currently up or down, it calls
pon
which calls pppd, which fails to connect. If I then go an execute the script from the CLI its fine.Any thoughts would be very much appreciated -this is doing my box in now.
#Syslog (on a failure): Dec 30 17:02:01 LogServer /USR/SBIN/CRON[4530]: (root) CMD (/bin/bash /root/scripts/vpnup.bash >> /root/scripts/vpn.log) Dec 30 17:02:01 LogServer pppd[4542]: pppd 2.4.4 started by root, uid 0 Dec 30 17:02:01 LogServer pppd[4542]: Couldn't get channel number: Input/output error Dec 30 17:02:01 LogServer pppd[4542]: Exit. #Cron Line * * * * * root /bin/bash /root/scripts/vpnup.bash >> /root/scripts/vpn.log
Update:
Works fine now. I was calling my cron entry via /etc/cron.d/vpn which originally looked like:
MAILTO=root * * * * * root /bin/bash /root/scripts/vpnup.pl >> /root/scripts/vpn.log
Now that its been changed, pptp works perfectly :-D
MAILTO=root SHELL=/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin * * * * * root perl /root/scripts/vpnup.pl >> /root/scripts/vpn.log
many thanks to Justin for giving examples :)
-
BuildTheRobots over 14 yearsThanks for the response. I will try adding path statements into the cron entry for my script and see if there is any change. The idea of creating a loop is a good workaround, though I was trying to avoid it in case my script crashed or whatever. I like that you've called my script from another script which should add some resilience. I was wondering if I should be creating my own daemon (to run via init) that monitors the VPN, or would that just be overkill?
-
BuildTheRobots over 14 yearsyeah, the path statement helps (and calling it via both bash and perl probably helps too) -thank you :-D
-
Justin over 14 yearsCool :-) A daemon is probably overkill as long as cron works. I tend to use daemontools or for things that have to be running 24/7 or things that have to run in say, 10 minute intervals, but might regularly take longer than 10 minutes to run.