#!/bin/sh
#
# First, initialize some variables...
#
HOST=Vanderbilt.edu	# the PPP server host
REDIAL_TIME=		# initialize the redial time
INIT_STR=AT\&F1		# init string for the USR Sportster - sets to factory defaults
DIAL_COUNT=			# initialize the redial counter
PHONE=				# the phone line we're calling
PHONE_COUNT=		# to keep track of the line we're calling

####################	Banner()	#######################################
# Banner() displays the opening banner
#
Banner() {
echo -n "  




                             PPP Redialer v. 0.11
                                15 July 1995

                                     by

                                John M. Fisk










                                  

Please enter REDIAL_TIME [in seconds] below.
ENTER:"
read REDIAL_TIME

}
# END Banner()
###############################################################################

###################	Dial_msg_1()	#######################################
#
Dial_msg() {
echo "

               
		PPP RE-DIALER 

		ATTEMPTING TO DIAL......$HOST
		PHONE LINE..............$PHONE
		DIAL ATTEMPT............$DIAL_COUNT
		REDIAL INTERVAL.........$REDIAL_TIME


		Hit ctrl-C to quit.

"
}
# END Dial_msg()
###############################################################################

#####################	Main Program	#######################################
#
# Now, begin the main part of the program.

echo $INIT_STR > /dev/cua1		# initialize the modem
clear							# clear the screen
Banner							# issue the opening banner and get REDIAL_TIME
DIAL_COUNT=1					# set the dial counter

while [ "$DIAL_COUNT" -le "5" ]		# while dial count is less than 5
do 
	case "$DIAL_COUNT" in
		"1" ) PHONE=123-1234; clear; Dial_msg; pppd connect 'chat -f /usr/lib/ppp/vandy1' /dev/cua1 38400 ;;
		"2" ) PHONE=123-1235; clear; Dial_msg; pppd connect 'chat -f /usr/lib/ppp/vandy2' /dev/cua1 38400 ;;
		"3" ) PHONE=123-1236; clear; Dial_msg; pppd connect 'chat -f /usr/lib/ppp/vandy3' /dev/cua1 38400 ;;
		"4" ) PHONE=123-1237; clear; Dial_msg; pppd connect 'chat -f /usr/lib/ppp/vandy4' /dev/cua1 38400 ;;
		"5" ) PHONE=123-1238; clear; Dial_msg; pppd connect 'chat -f /usr/lib/ppp/vandy5' /dev/cua1 38400 ;;
	esac

	if [ "$?" -eq "0" ]; then
		exit 0								# if exit status = 0 then it connected
	else
		sleep 1								# sleep for 1 second
		DIAL_COUNT=`expr $DIAL_COUNT + 1`	# augment the dial counter
	fi
done

# At this point, we've quickly cycled through all five numbers.  From here on
# we'll have to start the periodic redial loop until a connection is made.
#

PHONE_COUNT=1							# keep track of which line to call
DIAL_COUNT=`expr $DIAL_COUNT + 1`		# augment dial counter

while [ "$?" -ne "0" ]					# if chat cannot connect...
do
	case "$PHONE_COUNT" in
		"1" ) PHONE=123-1234; clear; Dial_msg; pppd connect 'chat -f /usr/lib/ppp/vandy1' /dev/cua1 38400 ;;
		"2" ) PHONE=123-1235; clear; Dial_msg; pppd connect 'chat -f /usr/lib/ppp/vandy2' /dev/cua1 38400 ;;
		"3" ) PHONE=123-1236; clear; Dial_msg; pppd connect 'chat -f /usr/lib/ppp/vandy3' /dev/cua1 38400 ;;
		"4" ) PHONE=123-1237; clear; Dial_msg; pppd connect 'chat -f /usr/lib/ppp/vandy4' /dev/cua1 38400 ;;
		"5" ) PHONE=123-1238; clear; Dial_msg; pppd connect 'chat -f /usr/lib/ppp/vandy5' /dev/cua1 38400 ;;
	esac

	if [ "$?" -eq "0"]; then
		exit 0
	else
		PHONE_COUNT=`expr $PHONE_COUNT + 1`		# augment phone counter
		sleep $REDIAL_TIME						# sleep for the requested time
		if [ "$PHONE_COUNT" -gt "5" ]; then		# cycle back once count > 5
			PHONE_COUNT=1
		fi
	fi
done
