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 ]
> (command to kill pppd)
> sleep 5
> (command to restart pppd)
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 (188.8.131.52): 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
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.
# 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
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:184.108.40.206 P-t-P:220.127.116.11 Mask:255.255.255.0
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 "18.104.22.168" and exit with an exit code of 0
(success), which causes the script to exit immediately ("&& exit 0").
If grep doesn't find "22.214.171.124" then it will exit with a non-zero exit
code (failure), and execution of the script will continue at the following
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.
* Unix Consulting: Installation, Configuration, & Support. *
* --- Also, contact me if you need your Dos/Win/OS2 LAN connected to --- *
* --- the Internet. --- *