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 EXAMPLE
  101. The following
  102. .B rc
  103. script dials out through a Hayes compatible modem on
  104. .B /dev/eia1
  105. and lets the user type in a user name and password
  106. before starting
  107. .BR ppp .
  108. .EX
  109. #!/bin/rc
  110. dev=/dev/eia1
  111. telno=18005551212
  112. fn initfn {
  113. dial/drain
  114. echo +++
  115. dial/at zh0
  116. }
  117. fn dialfn {
  118. dial/drain
  119. dial/at dt^$telno
  120. }
  121. {
  122. # set up uart
  123. if( test -e $dev^ctl ){
  124. echo -n b^$baud
  125. echo -n m1 # cts/rts flow control
  126. echo -n q64000 # big buffer
  127. echo -n n1 # nonblocking writes
  128. echo -n r1 # rts on
  129. echo -n d1 # dtr on
  130. echo -n c1 # handup when we lose dcd
  131. } > $dev^ctl
  132. # get the modem's attention
  133. while( ! initfn )
  134. sleep 1
  135. # dial
  136. while( ! dialfn )
  137. sleep 30
  138. if( ! dial/expect -it 60 'username:' ){
  139. echo can''t connect >[1=2]
  140. exit connect
  141. }
  142. dial/pass
  143. if( ! dial/expect -it 60 'password:' ){
  144. echo can''t connect >[1=2]
  145. exit connect
  146. }
  147. dial/pass
  148. if( ! dial/expect -t 60 'ppp or telnet:' ){
  149. echo can''t connect >[1=2]
  150. exit connect
  151. }
  152. echo ppp
  153. dial/expect -t 5 something
  154. echo connected >[1=2]
  155. # start ppp
  156. ip/ppp $primary -f
  157. } < $dev > $dev
  158. .EE
  159. .SH FILES
  160. .B /rc/bin/ipconf/*
  161. example dialer scripts for ppp
  162. .SH SOURCE
  163. .B /sys/src/cmd/dial/*.c
  164. .SH SEE ALSO
  165. .IR ppp (8),
  166. .IR telco (4)