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

cronlinuxpoint-to-point-protocolvpn

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 😀

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 🙂

Best Answer

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