NAME
at, drain, expect, pass – dialer scripting tools

SYNOPSIS
dial/at [ –q ] [ –t seconds ] atcommand
dial/expect [ –iq ] [ –t seconds ] goodstring [ badstring... ]
dial/drain
dial/pass
[ –q ]

DESCRIPTION
These commands are used to write telephone dialing scripts, mostly for PPP sessions. They all expect standard input and output to be connected to a communications device, e.g, a serial line to a modem. They communicate with the user using /dev/cons.

At sends atcommand to the modem prefixed with the string at. It then reads from the modem expecting an AT response. At will return success if it gets and OK of CONNECT response. Otherwise it will return the response as an error status. The options are:
t    set the timeout to seconds. The default is 300.
q    don't write to /dev/cons what is read from standard in. The default is to copy everything through.

Expect reads standard input looking for one of the strings given as arguments. Reading the first string causes a successul exit status. Reading any of the others causes an exit status equal to the string. The command also terminates on a timeout. The options are:
t    set the timeout to seconds. The default is 300.
i    ignore case when doing the matches.
q    don't write to /dev/cons what is read from standard in. The default is to copy everything through.

Pass copies input from /dev/cons to standard output. It terminates on a newline. The only flag is –q and means the same as it does for expect.

Drain discards any input waiting on standard input. It is used to sync up the stream at the start of dialing or after an error.

EXAMPLE
The following rc script dials out through a Hayes compatible modem on /dev/eia1 and lets the user type in a user name and password before starting ppp.
#!/bin/rc
dev=/dev/eia1
telno=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

FILES
/rc/bin/ipconf/* example dialer scripts for ppp

SOURCE
/sys/src/cmd/dial/*.c

SEE ALSO
ppp(8), telco(4)
Copyright © 2017 Alcatel-Lucent. All rights reserved.