Subject: Re: PPP questions
To: John M Vinopal <banshee@gabriella.resort.com>
From: Michael L. VanLoon -- HeadCandy.com <michaelv@HeadCandy.com>
List: current-users
Date: 05/27/1996 22:34:37
>i use this as /etc/ppp/restart-ppp
>#!/bin/sh
># Try to restart pppd in case the modem has dropped.
>#
>/bin/sleep 60
>pppd
>
>
>and in options:
>disconnect '/etc/ppp/restart-ppp'


If you're interested, here are some scripts I accumulated using PPP
over the last couple years.  These, of course, are for the client
side, not the server side.  I wrote them all, in occasional fits of
energy...

     ---------- >8 ----- begin /root/bin/doppp ----- 8< ----------
#!/bin/sh

# Uncomment these if you can't do LCP echo "pings":
#/etc/ppp/pingtest.sh 1> /dev/null 2>&1 &
#export pingpid=$!
#trap "echo exiting doppp ; kill $pingpid ; exit" 0 1 3 15 1> /dev/null 2>&1

while [ 1 ] ;
do
	sync; sync; sync
	/usr/sbin/pppd connect /root/bin/dochat -detach
	sleep 7		# give things a chance to settle
#	sleep 15	# give things a chance to settle
done
     ---------- >8 -----  end /root/bin/doppp  ----- 8< ----------


     ---------- >8 ----- begin /root/bin/dochat ----- 8< ----------
#!/bin/sh

stty crtscts clocal -parity -ixon -ixany

# chat script stored in ~root/.ppp-chat:
chat -v -t 30 -f /root/.ppp-chat
     ---------- >8 -----  end /root/bin/dochat  ----- 8< ----------


     ---------- >8 ----- begin /root/bin/timedppp ----- 8< ----------
#!/bin/sh

/root/bin/doppp &

if [ $# -ge 1 ]; then
    ( sleep $1 ; kill $! ; kill -HUP `cat /var/run/ppp0.pid` ) &
fi
     ---------- >8 -----  end /root/bin/timedppp  ----- 8< ----------


     ---------- >8 ----- begin /etc/ppp/pingtest.sh ----- 8< ----------
#!/bin/sh
#
# pingtest.sh
#
# To be used if you can't use LCP echo "ping" packets.
#
# Sends a single ping to the remote ppp router and checks for success.
# If it fails, kills the active pppd, and waits for it to establish a
# new connection.  If success, or once a new connection is established, 
# it waits 60 seconds and repeats the whole process.
#
# Only checks ppp0.  It probably wouldn't be difficult to make it
# either loop over all ppp interfaces, or make it pick up its ppp
# interface from a /var/run/ file, and have the spawning shell spawn
# multiples of this script, one for each interface.
#
# By Michael VanLoon <michaelv@HeadCandy.com>, 12/16/95
#

while [ 1 ]; do
	# only do this stuff when the link is up:
	if [ -f /var/run/ppp0.pid ]; then
		# send a test packet to the other side:
		ping -c 1 -s 8 -n -q -w 10 `cat /var/run/ppp0.remote-ip` \
			1> /dev/null 2>&1

		if [ $? -eq 1 ]; then
			# link is hung -- kill pppd so it can be revived:
			kill -HUP `cat /var/run/ppp0.pid` 1> /dev/null 2>&1

			# allow pppd to hangup, cleanup, and exit:
			sleep 10

			# spin here until the link comes back up:
			while [ ! -f /var/run/ppp0.pid ]; do
				sleep 1
			done
		fi
	fi

	# do it all again in 30 seconds:
	sleep 30
done
     ---------- >8 -----  end /etc/ppp/pingtest.sh  ----- 8< ----------


     ---------- >8 ----- begin /etc/ppp/ip-up ----- 8< ----------
#!/bin/sh
#  ip-up
#
# Commands to execute on establishment of IPCP
#
# order of parameters:
# interface-name  tty-device  speed  local-IP-address  remote-IP-address

echo `date` >> /tmp/ip-up-debug
echo $0 $1 $2 $3 $4 $5 >> /tmp/ip-up-debug

echo `date "+%Y%m%d %H%M%S"` $1 $2 $5 $4 logon >> /var/log/ppplog

rm -f /var/run/$1.remote-ip
echo $5 > /var/run/$1.remote-ip

# Uncomment these if you can't do LCP echo "pings":
# Actually, don't uncomment these -- moved to doppp script
#rm -f /var/run/$1.pt.pid
#/etc/ppp/pingtest.sh
#echo $! > /var/run/$1.pt.pid
     ---------- >8 -----  end /etc/ppp/ip-up  ----- 8< ----------


     ---------- >8 ----- begin /etc/ppp/ip-down ----- 8< ----------
#!/bin/sh
#  ip-down
#
# Commands to execute on finish of IPCP
#
# order of parameters:
# interface-name  tty-device  speed  local-IP-address  remote-IP-address

echo `date` >> /tmp/ip-down-debug
echo $0 $1 $2 $3 $4 $5 >> /tmp/ip-down-debug

echo `date "+%Y%m%d %H%M%S"` $1 $2 $5 $4 logoff >> /var/log/ppplog

#if [ -f /var/run/$1.pt.pid ]; then
#	kill -HUP `cat /var/run/$1.pt.pid`
#	rm -f /var/run/$1.pt.pid
#fi

#if [ -f /var/run/$1.pid ]; then
#    kill -HUP `cat /var/run/$1.pid` 1> /dev/null 2>&1
#fi

rm -f /var/run/$1.remote-ip
     ---------- >8 -----  end /etc/ppp/ip-down  ----- 8< ----------


Replace "1234567" with your dial-in modem number, USERNAME with the
login name, and PASSWORD with the password you log into the ppp server
with, below:
     ---------- >8 ----- begin sample ~root/.ppp-chat ----- 8< ----------
TIMEOUT 10 ABORT BUSY ABORT 'NO CARRIER' ABORT 'NO DIALTONE' ABORT 'NO ANSWER' ABORT 'Invalid Login' ABORT 'PROTOCOL: NONE' '' AT OK-AT-OK ATDT1234567 TIMEOUT 40 CONNECT '' TIMEOUT 10 ogin:--ogin: USERNAME ssword: PASSWORD\q 'PPP session' \d\d
     ---------- >8 -----  end  sample ~root/.ppp-chat----- 8< ----------


-----------------------------------------------------------------------------
  Michael L. VanLoon                                 michaelv@HeadCandy.com
        --<  Free your mind and your machine -- NetBSD free un*x  >--
    NetBSD working ports: 386+PC, Mac 68k, Amiga, Atari 68k, HP300, Sun3,
        Sun4/4c/4m, DEC MIPS, DEC Alpha, PC532, VAX, MVME68k, arm32...
    NetBSD ports in progress: PICA, others...

   Roll your own Internet access -- Seattle People's Internet cooperative.
                  If you're in the Seattle area, ask me how.
-----------------------------------------------------------------------------