LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 08-30-2011, 07:10 PM   #1
JeffElkins
LQ Newbie
 
Registered: Sep 2007
Posts: 18

Rep: Reputation: 0
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
 
Old 08-30-2011, 08:30 PM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,053

Rep: Reputation: 484Reputation: 484Reputation: 484Reputation: 484Reputation: 484
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
 
Old 08-30-2011, 11:57 PM   #3
JeffElkins
LQ Newbie
 
Registered: Sep 2007
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jlinkels View Post
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?
 
Old 08-31-2011, 12:44 AM   #4
hi2arun
Member
 
Registered: Apr 2010
Distribution: Fedora
Posts: 109
Blog Entries: 4

Rep: Reputation: 33
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.

Last edited by hi2arun; 08-31-2011 at 12:45 AM.
 
Old 08-31-2011, 04:49 AM   #5
JeffElkins
LQ Newbie
 
Registered: Sep 2007
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by hi2arun View Post
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.
 
Old 08-31-2011, 10:22 AM   #6
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,053

Rep: Reputation: 484Reputation: 484Reputation: 484Reputation: 484Reputation: 484
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
 
Old 12-08-2013, 08:20 PM   #7
rsmithee
LQ Newbie
 
Registered: Dec 2013
Posts: 2

Rep: Reputation: Disabled
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Check SELinux Status (NO GUI) carlosinfl Red Hat 15 01-13-2011 05:24 PM
security updates check/status wjtaylor Linux - Security 1 08-25-2010 08:33 PM
How to check RAID status? tikit Linux - Hardware 5 07-16-2009 03:37 PM
Check disk status diezjc Linux - Hardware 2 04-06-2006 03:58 PM
Check Printer Status Debby Linux - General 5 02-08-2002 08:52 PM


All times are GMT -5. The time now is 07:11 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration