Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 :)

share|improve this question

2 Answers 2

up vote 4 down vote accepted
+150

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
share|improve this answer
1  
Thanks 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 Jan 2 '10 at 23:39
1  
yeah, the path statement helps (and calling it via both bash and perl probably helps too) -thank you :-D –  BuildTheRobots Jan 3 '10 at 0:01
    
Cool :-) 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. –  Justin Jan 3 '10 at 0:05

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.