[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: pppd problem -- modem *not* disconnecting when connection lost.

On Tue, 30 Jan 1996, Kevin M Bealer wrote:

> ping -c 1 www.sgi.com | grep "received" > $HOME/ooga
> if [ ! -s $HOME/ooga ]
> then
> 	(command to kill pppd)
> 	sleep 5
> 	(command to restart pppd)
> fi

The trouble with that script is that ping's output will always contain
the word "received".  Here's an example (my annex is currently powered
down - I don't need 16 text terminals here at home right now :-)

$ ping -c 1 annex
PING annex.taz.net.au ( 56 data bytes

--- annex.taz.net.au ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss

It's much better to check the interface using ifconfig...

So, ping isn't a particularly good method of testing whether your PPP link
is up.

Here's what I run from cron every 5 minutes.  Note that it won't detect
a stuck pppd process (as has already been posted, the lcp-echo* options
are good for that), but is a good general solution for testing whether
the ppp interface is up or not.

---cut here


# if link is up, exit immediately.
/sbin/ifconfig | /usr/bin/grep $REMOTE_IP >/dev/null 2>&1 && exit 0


/usr/sbin/pppd /dev/$DEVICE $SPEED
---cut here---

The output of ifconfig is piped into grep.  If the ppp link is up, then
there will be an interface which looks like this:

ppp0      Link encap:Point-Point Protocol  
          inet addr:  P-t-P:  Mask:
          UP POINTOPOINT RUNNING  MTU:1500  Metric:1
          RX packets:20185 errors:3 dropped:3 overruns:0
          TX packets:23042 errors:0 dropped:0 overruns:0

and grep will find "" and exit with an exit code of 0
(success), which causes the script to exit immediately ("&& exit 0").

If grep doesn't find "" then it will exit with a non-zero exit
code (failure), and execution of the script will continue at the following

This works.

Note that this script can be called from cron or run at the command
line.  If the link's alreay up, then nothing happens. if it's down then
it's started up.


  cas@muffin.pronet.com                                cas@muffin.apana.org.au
   *       Unix Consulting:  Installation, Configuration, & Support.        *
   * --- Also, contact me if you need your Dos/Win/OS2 LAN connected to --- *
   * --- the Internet.                                                  --- *

Reply to: