On 19 Aug 2003 18:51:35 -0700, Gabriel Michael <(E-Mail Removed)> wrote:
> Hello,
>
> I'm looking for a way to have a bash shell script check to see if a
> particular ppp link is up (ppp0), and if so, output "1", if not,
> output "0"... my (messy) idea was:
>
> ping -c 1 host.i.want.to.ping | grep -c "0% loss"
>
> This outputs a "1" if the host is up... then I'd assign that value to
> a variable, and test the variable, and output 1 or 0 based on that.
> I'm sure there's a better way to do this, but my mind is blanking...
Unless you have a flaky ISP with routing problems, it would be better to
just determine if pppd is connected or not instead of constantly pinging
an outside host (which may not like that). You cannot use ifconfig
output to tell status of demand pppd (since ppp0 is up whether connected
or waiting to be triggered).
When I used demand dialup pppd, I wrote write my local IP to a file
(/etc/ppp/stat) from /etc/ppp/ip-ip (or ip-up.local) and similarly wrote a
zero to that file from ip-down (or ip-down.local). In SuSE ip-down.local
was a symlink to ip-up.local and it used a case to determine if it was
coming up or down. Then I simply checked if the contents of the
/etc/ppp/stat file was greater than zero to tell if I was connected.
For example /etc/ppp/ip-up.local (and ip-down.local symlink):
#!/bin/sh
BASENAME=${0##*/}
INTERFACE=$1
DEVICE=$2
SPEED=$3
LOCALIP=$4
REMOTEIP=$5
# demand pppd status
case "$BASENAME" in
ip-up*)
echo $LOCALIP > /etc/ppp/stat
# update dynamic DNS (older no-ip.com binary then)
/usr/local/bin/noip
;;
ip-down*)
echo 0 > /etc/ppp/stat
;;
*)
;;
esac
Sample shell script to tell if I was online:
#!/bin/sh
FILE="/etc/ppp/stat"
if [ ! -r "$FILE" ]; then
echo "$FILE not found or unreadable"
exit 1
fi
STATUS=`cat "$FILE"`
if [ "$STATUS" = "0" ]; then
echo "pppd is not connected"
else
echo "pppd ip: $STATUS"
fi
--
David Efflandt - All spam ignored
http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/