LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   check vpn status (http://www.linuxquestions.org/questions/linux-networking-3/check-vpn-status-900320/)

JeffElkins 08-30-2011 07:10 PM

check vpn status
 
I'm trying to check the status of a vpn connection. The script below works from the console, but fails from crontab. ???

Thanks for any help.


Code:

#!/bin/bash

IFCONFIG="/sbin/ifconfig ppp"

PPPUP=`$IFCONFIG | grep "UP" | wc -l`;

if test $PPPUP -gt 0;
 then
  echo "ppp up";
else
/usr/bin/pon;
echo "bringing up ppp";
fi


jlinkels 08-30-2011 08:30 PM

Silly question but do you run it from crontab with root permissions?
Have you checked /var/log/syslog for this job, did the job run at all, or did it fail?

jlinkels

JeffElkins 08-30-2011 11:57 PM

Quote:

Originally Posted by jlinkels (Post 4457512)
Silly question but do you run it from crontab with root permissions?
Have you checked /var/log/syslog for this job, did the job run at all, or did it fail?

jlinkels

Thanks for the reply, I didn't think about permissions. The script runs and is called from root's crontab, I thought that was sufficient as far as permissions go. However, changing the script to sudo /usr/bin/pon seems to fix things. Is there a better way to go about this?

hi2arun 08-31-2011 12:44 AM

Did you try setting 'suid' bit for /usr/bin/pon? Perhaps, that should help.

If not, the other simple way of doing this is, run the script in an infinite loop with proper sleep. So the script will be running all the time doing things for you.

JeffElkins 08-31-2011 04:49 AM

Quote:

Originally Posted by hi2arun (Post 4457626)
Did you try setting 'suid' bit for /usr/bin/pon? Perhaps, that should help.

If not, the other simple way of doing this is, run the script in an infinite loop with proper sleep. So the script will be running all the time doing things for you.

Thanks for the reply. Setting suid on pon (itself a script that calls pppd) didn't do the trick. But adding the sudo to the call to /usr/bin/pon works fine, so problem solved. It's still a puzzle why something called from root's crontab fails w/o the sudo. Btw, pppd does have the suid bit set.

jlinkels 08-31-2011 10:22 AM

If /usr/bin/pon is a script, it is better to call explicitely /bin/bash /usr/bin/pon. In general, use an absolute path on everything in cron.

Did you set rwxr-xr-x permissions for /usr/bin/pon? If not, even root cannot execute it. (Just guessing, too lazy to try it) Anyway, I have stopped by calling scripts depending on #!/bin/bash or #!/bin/sh on the first line. Just call a script with /bin/bash so you are sure that (a) bash is used to execute and (b) you don't have to discover that you forgot execute permissions.

jlinkels

rsmithee 12-08-2013 08:20 PM

In case anyone finds this thread in the future, I put together something along these lines that turned into a pet project. It's basically a 'VPN companion' script that checks the system in a few different ways to see if the VPN has dropped or what-have-you. I wrote it for a CentOS 6 system, but it's pretty well commented in case it needs to be tailored for another distro or different uses.

hXXp://code.google.com/p/ipcheck/source/browse/ipcheck.sh


All times are GMT -5. The time now is 02:52 AM.