Subject: Re: chat script that redials
To: Ken Nakata <kenn@remus.rutgers.edu>
From: Ken Nakata <kenn@remus.rutgers.edu>
List: macbsd-general
Date: 05/03/1995 19:57:03
Okay, here's what I got. It's David Leonard's work. I suppose
you have to change it a little bit to suit your site's setting,
but you get the idea.
Have fun, and thanks David :-)
Ken
Included scripts written by:
David Leonard BE(Comp)/BCompSc 5th year student
The University of Queensland s160828@student.uq.edu.au
----<scripts start here>----
rc.local: (extract)
========
( while :; do /etc/ppp/ppp-on; done )& # should change this one day
ppp-on:
======
#!/bin/sh
#
# ppp-on
#
# Set up a PPP link
#
DEBUG=-d
CHATOPTS=-v
DIR=`dirname $0`
ME=`basename $0`
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$DIR; export PATH
if [ $# -eq 0 ]; then
SYSTEM=DEFAULT
else
SYSTEM=$1
shift
fi
if [ ! -f $DIR/system/$SYSTEM ]; then
echo "$DIR/system/$SYSTEM: no connect program for $SYSTEM" >&2
exit 1
fi
DEVICE=modem
#DEVICE=printer # has higher interrupt priority
BAUD=19200
ADDRESS=
eval `egrep '^(DEVICE|BAUD|ADDRESS)=' $DIR/system/$SYSTEM`
if [ -f $LOCKDIR/LCK..$DEVICE ]
then
echo "$ME: $DEVICE: locked"
exit 1
fi
chown root /dev/$DEVICE
chmod 600 /dev/$DEVICE
stty -f /dev/$DEVICE clocal -tostop
# propagate shell flags to the chat script
opts=-$-
[ "x$opts" = "x-" ] && opts=
exec \
pppd \
$DEBUG \
modem \
lock \
$BAUD \
connect "/bin/sh $opts $DIR/system/$SYSTEM $CHATOPTS" \
mru 1500 \
lcp-echo-interval 60 \
defaultroute \
$ADDRESS \
/dev/$DEVICE \
-detach
DEFAULT -> prentice
=======
prentice
========
#!/bin/sh
#
# Prentice center PPP login script
#
BAUD=19200
ADDRESS=s160828:
PHONE="3654900 8703227 3654055 3654916"
USER=s160828
PASSWORD='my-password-usually-goes-here'
INIT='M1S7=255&K3&D2&C1X4'
# m1 : low volume
# s7=255: 255 seconds to wait for carrier
# &k5 : cts/rts flow control (ha what a joke)
# &d2 : hang up when modem control (dtr) dropped
# &c1 : CD follows modem carrier state
# x4 : extended dial responses
VERBOSE=-v ;
stty -ixon -ixoff -ixany -crtscts
umask 077
TMP="/tmp/chat_$$_$ADDRESS"
while :; do
#
# choose a random phone number to ring
case `perl -e 'srand;print int(rand(4))'` in
0) phone=3654900 ;;
1) phone=3654916 ;;
2) phone=3654055 ;;
3) phone=8703227 ;;
esac
sed 's/[ ]*#.*//' >$TMP <<eof
#
# Set up the abort strings. These cause the chat script
# to exit immediately.
#
ABORT "NO CARRIER"
ABORT "BUSY"
ABORT "NO ANSWER"
ABORT "NO DIALTONE"
#
# Verify the existence of the modem.
# If we don't get an OK back from ATZ straight away,
# we try the +++ escape sequence.
#
"" "ATZ"
TIMEOUT 10
"OK-\\d+++\\c-OK-ATZ-OK" ""
#
# Ensure the modem is hung up, and initialised, then
# dial the prentice centre. The prentice center may
# ring out if it is full, so we set the timeouts high.
# See also the S7 register in the init string.
#
"" "AT${INIT}HD${phone}" # init & dial
TIMEOUT 400 # a BIG timeout
"CONNECT" "\d" # pause after connect
#
# We are connected to an annex.
# The annex prompts with:
#
# Annex Username: username
# Annex Password: password
#
# and either spits back:
#
# Username/Password Incorrect
# or
# Permission granted...annex:
#
# Occasionally, the annex will have a buffer full
# of crap, which distorts the Username field,
# so we send some x's to counter it
#
TIMEOUT 5
"name:-x-name:-x-name:-x-name:" "$USER" # send real username
"ssword:" "\\q${PASSWORD}" # and real password
TIMEOUT 20 # sometimes annex is slow
#
# Hopefully, we're logged into the annex and we can
# set up stuff to do ppp
#
"annex:" "\\qstty -climask7" # don't mask 7bit
"annex:" "stty iflow none" # no input fc
"annex:" "stty oflow none" # no output fc
"annex:" "ppp" # start ppp
eof
if chat \
$* \
-f $TMP
#-l $LOCKF
then
stty hupcl -clocal
trap "" 0 1 2 15
exit 0
else
sleep 10
fi
done