LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   detect lost ppp connection (https://www.linuxquestions.org/questions/linux-newbie-8/detect-lost-ppp-connection-391632/)

rubella 12-11-2005 03:42 PM

detect lost ppp connection
 
hey folks!

i make a connection with the company through a pptp connection. They have the server, i'm the client... sometimes, i loose my connection (every 4 days). i don't know why...

does someone has a script (cron?) to detect when connection has been lost and to reconnect over ppp?

now, i use 'pon companyname' to connect and use ifconfig to check connectivity...
thx!

zeos 12-11-2005 09:31 PM

It'd be pretty trivial to throw together a small shell script which could be called from cron to check the network status, I've used fping (www.fping.com ) to do pretty much this same thing (can't use normal ping on this one as we need (preferably) an easy way to get the results back to the shellscript..fping does this nicely ;)

Install fping, then create a shell script:
Code:

#!/bin/bash

HOST="xxx.xxx.xxx.xxx" # <=IP of the server you're connecting to

if fping $HOST; then
exit
else
pon companyname
fi

Save and chmod +x the file and stick it somewhere, run it from crontab however often you need....

uberNUT69 12-12-2005 01:58 AM

I suggest you take a look at /etc/ppp/options.
Specifically, these options:
persist
maxfail
holdoff

Here's a nice description:
http://www.linux.com/guides/nag2/x7297.shtml

You can put these options in the relevant peers file
rather than specifying it globaly in 'options'.

rubella 12-12-2005 03:13 AM

hey guys, thx for the solutions!
the persist option was allready there in my peers file, i add the other ones too!
maxfail 0
holdoff 20

to be sure this goddamn connection never goes down again, i'll apply previous script to my cron... :)

uberNUT69 12-12-2005 03:59 AM

Watch out for your call costs with maxfail=0!!!

uberNUT69 12-12-2005 04:16 AM

You might want to grep your syslog to find out why it's hanging up.
Is it server timeout, hangup on inactivity ... ?
You might find, as your persist option was already set
that maxfail was defaulting to 10 and that
10 x (max session time) = ~4 days ???

With maxfail=0, for example, a problem at their end would mean constant
redials (until you're poor ;) )

iceman47 12-12-2005 05:27 AM

if everthing else fails, add this to crontab (crontab -e as root)
0 * * * * poff <provider> && pon <provider>

this will terminate $ reinitialize the ppp connection every day @ 00:00, change crontab to your liking ;)

...or you could use a script like this:
Code:

#!/usr/bin/perl
# $iptocheck is the remote ip of the tunnel, we can safely assume if this isn't available
# in the ip list, the tunnel isn't there either.

$iptocheck = "192.168.1.1/32";

$rc = system('ip a | grep '.$iptocheck.' 2>&1> /dev/null');
if ($rc eq 0)
{
        $date=`date`;
        chomp($date);
        `echo '$date -> ok' >> <logfile>`;
}
else
{
        `/usr/bin/poff <provider>`;
        `/usr/bin/pon <provider>`;
        $date=`date`;
        chomp($date);
        `echo '$date -> tunnel gone' >> <logfile>`;
}

Note: don't forget to supply the full path for pptp in /etc/ppp/peers/<provider>.

rubella 12-12-2005 05:40 AM

Iceman, this one is so cool! thx mate, i owe you a beer!

Ubernut: it's a free connection... :D and for you a beer too ;)


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