1
0

expect 3.0 KB

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