#!/bin/bash # to start pppd and test for connection # # $0 holds the command entered #echo $0 #dcount counts the number of times dialed dcount=0 dcount=$((dcount)) # there will be a route using ppp0 if the connection already exists if [ -n "$(/sbin/route -n | grep 'ppp[0]')" ] then echo 'Connected.' else # otherwise, we need to tell pppd to dial # the attempt to dial should repeat so long as pppd is not running while [ -z "$(ps ax | grep 'ppp[d]')" ] do t="$(ps ax | grep 'ppp[d]')" echo $t echo 'Dialing...' dcount=$((dcount+1)) echo ${dcount} exec /usr/sbin/pppd call ${1:-provider} & while [ -n "$(ps ax | grep 'ppp[d]')" ] && \ [ -z "$(/sbin/route -n | grep 'ppp[0]')" ] do if [ -n "$(pidof chat)" ] then tail --pid=$(pidof chat) -n 1 -f /var/log/ppp.log | \ grep " ATDT\|CARRIER \|Connect\|Failed" fi done # something happened to pppd (busy? no carrier? what?) if [ -z "$(ps ax | grep '\/sbin\/ppp[d]')" ] then t="$(ps ax | grep '\/sbin\/ppp[d]')" else t="$(/sbin/route -n | grep 'ppp[0]')" echo $t if [ -n "$(/sbin/route -n | grep 'ppp[0]')" ] then # success: pppd is running AND a route is using ppp0 echo "Got it!" fi fi done fi