expect 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. .TH EXPECT 1
  2. .SH NAME
  3. at, drain, expect, pass \- dialer scripting tools
  4. .SH SYNOPSIS
  5. .B dial/at
  6. [
  7. .B -q
  8. ] [
  9. .B -t
  10. .I seconds
  11. ]
  12. atcommand
  13. .br
  14. .B dial/expect
  15. [
  16. .B -iq
  17. ] [
  18. .B -t
  19. .I seconds
  20. ]
  21. .I goodstring
  22. [
  23. .IR badstring ...
  24. ]
  25. .br
  26. .B dial/drain
  27. .br
  28. .B dial/pass
  29. [
  30. .B -q
  31. ]
  32. .SH DESCRIPTION
  33. These commands are used to write telephone dialing
  34. scripts, mostly for PPP sessions. They all expect standard input and
  35. output to be connected to a communications device, e.g,
  36. a serial line to a modem. They communicate with the user using
  37. .BR /dev/cons .
  38. .PP
  39. .I At
  40. sends
  41. .B atcommand
  42. to the modem prefixed with the string
  43. .BR at .
  44. It then reads from the modem expecting an AT response.
  45. .I At
  46. will return success if it gets and
  47. .B OK
  48. of
  49. .B CONNECT
  50. response. Otherwise it will return the response as an
  51. error status. The options are:
  52. .TP
  53. .B -t
  54. set the timeout to
  55. .IR seconds .
  56. The default is 300.
  57. .TP
  58. .B -q
  59. don't write to
  60. .B /dev/cons
  61. what is read from standard in. The default is
  62. to copy everything through.
  63. .PD
  64. .PP
  65. .I Expect
  66. reads standard input looking for one of the strings given
  67. as arguments. Reading the first string causes a successul exit
  68. status. Reading any of the others causes an exit status equal to
  69. the string. The command also terminates on a timeout. The options
  70. are:
  71. .TP
  72. .B -t
  73. set the timeout to
  74. .IR seconds .
  75. The default is 300.
  76. .TP
  77. .B -i
  78. ignore case when doing the matches.
  79. .TP
  80. .B -q
  81. don't write to
  82. .B /dev/cons
  83. what is read from standard in. The default is
  84. to copy everything through.
  85. .PD
  86. .PP
  87. .I Pass
  88. copies input from
  89. .B /dev/cons
  90. to standard output.
  91. It terminates on a newline. The only flag is
  92. .B -q
  93. and means the same as it does for
  94. .IR expect .
  95. .PP
  96. .I Drain
  97. discards any input waiting on standard input. It
  98. is used to sync up the stream at the start of dialing
  99. or after an error.
  100. .SH FILES
  101. .B /rc/bin/ipconf/*
  102. example dialer scripts for ppp
  103. .SH SOURCE
  104. .B /sys/src/dial/*.c
  105. .SH SEE ALSO
  106. .IR ppp (8),
  107. .IR telco (4)
  108. .SH EXAMPLE
  109. The following
  110. .B rc
  111. script dials out through a Hayes compatible modem on
  112. .B /dev/eia1
  113. and lets the user type in a user name and password
  114. before starting
  115. .BR ppp .
  116. .EX
  117. #!/bin/rc
  118. dev=/dev/eia1
  119. telno=18005551212
  120. fn initfn {
  121. dial/drain
  122. echo +++
  123. dial/at zh0
  124. }
  125. fn dialfn {
  126. dial/drain
  127. dial/at dt^$telno
  128. }
  129. {
  130. # set up uart
  131. if( test -e $dev^ctl ){
  132. echo -n b^$baud
  133. echo -n m1 # cts/rts flow control
  134. echo -n q64000 # big buffer
  135. echo -n n1 # nonblocking writes
  136. echo -n r1 # rts on
  137. echo -n d1 # dtr on
  138. echo -n c1 # handup when we lose dcd
  139. } > $dev^ctl
  140. # get the modem's attention
  141. while( ! initfn )
  142. sleep 1
  143. # dial
  144. while( ! dialfn )
  145. sleep 30
  146. if( ! dial/expect -it 60 'username:' ){
  147. echo can''t connect >[1=2]
  148. exit connect
  149. }
  150. dial/pass
  151. if( ! dial/expect -it 60 'password:' ){
  152. echo can''t connect >[1=2]
  153. exit connect
  154. }
  155. dial/pass
  156. if( ! dial/expect -t 60 'ppp or telnet:' ){
  157. echo can''t connect >[1=2]
  158. exit connect
  159. }
  160. echo ppp
  161. dial/expect -t 5 something
  162. echo connected >[1=2]
  163. # start ppp
  164. ip/ppp $primary -f
  165. } < $dev > $dev
  166. .EE