172 lines · 2.9 KB · Text
RawDownload
.TH EXPECT 1.SH NAMEat, drain, expect, pass \- dialer scripting tools.SH SYNOPSIS.B dial/at[.B -q] [.B -t.I seconds]atcommand.br.B dial/expect[.B -iq] [.B -t.I seconds].I goodstring[.IR badstring ...].br.B dial/drain.br.B dial/pass[.B -q].SH DESCRIPTIONThese commands are used to write telephone dialingscripts, mostly for PPP sessions.  They all expect standard input andoutput to be connected to a communications device, e.g,a serial line to a modem.  They communicate with the user using.BR /dev/cons ..PP.I Atsends.B atcommandto the modem prefixed with the string.BR at .It then reads from the modem expecting an AT response. .I Atwill return success if it gets and.B OKof.B CONNECTresponse.  Otherwise it will return the response as anerror status.  The options are:.TP.B -tset the timeout to.IR seconds .The default is 300..TP.B -qdon't write to.B /dev/conswhat is read from standard in.  The default isto copy everything through..PD.PP.I Expectreads standard input looking for one of the strings givenas arguments.  Reading the first string causes a successul exitstatus.  Reading any of the others causes an exit status equal tothe string.  The command also terminates on a timeout.  The optionsare:.TP.B -tset the timeout to.IR seconds .The default is 300..TP.B -iignore case when doing the matches..TP.B -qdon't write to.B /dev/conswhat is read from standard in.  The default isto copy everything through..PD.PP.I Passcopies input from.B /dev/consto standard output.It terminates on a newline.  The only flag is.B -qand means the same as it does for.IR expect ..PP.I Draindiscards any input waiting on standard input.  Itis used to sync up the stream at the start of dialingor after an error..SH EXAMPLEThe following.B rcscript dials out through a Hayes compatible modem on.B /dev/eia1and lets the user type in a user name and passwordbefore starting.BR ppp ..EX#!/bin/rcdev=/dev/eia1telno=18005551212 fn initfn {	dial/drain	echo +++	dial/at zh0} fn dialfn {	dial/drain	dial/at dt^$telno}{	# set up uart	if( test -e $dev^ctl ){		echo -n b^$baud		echo -n m1	# cts/rts flow control		echo -n q64000	# big buffer		echo -n n1	# nonblocking writes		echo -n r1	# rts on		echo -n d1	# dtr on		echo -n c1	# handup when we lose dcd	} > $dev^ctl 	# get the modem's attention	while( ! initfn )		sleep 1 	# dial	while( ! dialfn )		sleep 30			if( ! dial/expect -it 60 'username:' ){		echo can''t connect >[1=2]		exit connect	}	dial/pass	if( ! dial/expect -it 60 'password:' ){		echo can''t connect >[1=2]		exit connect	}	dial/pass	if( ! dial/expect -t 60 'ppp or telnet:' ){		echo can''t connect >[1=2]		exit connect	}	echo ppp	dial/expect -t 5 something	echo connected >[1=2] 	# start ppp	ip/ppp $primary -f} < $dev > $dev.EE.SH FILES.B /rc/bin/ipconf/*example dialer scripts for ppp.SH SOURCE.B /sys/src/cmd/dial/*.c.SH SEE ALSO.IR ppp (8),.IR telco (4)