home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / kermit / ker_scp3.zip / SCRIPTS.DOC < prev    next >
Text File  |  1988-09-11  |  21KB  |  460 lines

  1. [Following script-specific information is extracted from MS-Kermit's users
  2.  manual.  (V2.30 or so.)
  3.  
  4. 1.8. SCRIPTS
  5.  
  6. A  script is a file or a macro containing Kermit commands to be executed.  What
  7. distinguishes a script from ordinary TAKE files or macros is  the  presence  of
  8. INPUT,  REINPUT,  OUTPUT,  PAUSE,  ECHO,  CLEAR, IF, GOTO, and WAIT commands to
  9. automatically detect and respond to information flowing though the serial port,
  10. actions  which  otherwise  would  be performed by the user during CONNECT.  The
  11. login sequence of a host computer is a classical example.
  12.  
  13. It is a common, but incorrect, assumption that text to be sent  to  the  remote
  14. computer can be included in a TAKE file after the CONNECT command:
  15.  
  16.     set speed 9600      ; MS-Kermit command
  17.     connect          ; MS-Kermit command
  18.     run kermit          ; Text to be sent to other system
  19.     send foo.bar      ; Text to be sent to other system
  20.     ^]c              ; Escape sequence to get back to MS-Kermit
  21.     receive          ; MS-Kermit command
  22.  
  23. The  reason  this  doesn't  work is that during CONNECT, MS-Kermit always reads
  24. from the real keyboard, and not from the take file.  Even if this technique did
  25. work,  it  would  still  run  into  synchronization problems.  But these can be
  26. avoided when there is a way to coordinate the commands that we  send  with  the
  27. remote  system's  responses.    Kermit's  script commands provide this ability.
  28. They may be freely intermixed in a TAKE file or macro  with  any  other  Kermit
  29. commands to achieve any desired effect.  The OUTPUT command sends the specified
  30. characters as if the user had typed them; the INPUT command reads the responses
  31. and compares them with specified character strings, just as the user would do.
  32.  
  33. The  script commands include INPUT, REINPUT, OUTPUT, PAUSE, WAIT, ECHO, IF, and
  34. GOTO.  These commands may be interrupted by typing Ctrl-C at the keyboard.  The
  35. INPUT, REINPUT, PAUSE, and WAIT commands accept a following number as a timeout
  36. value. The number is interpreted as seconds from the present or,  if  given  in
  37. hh:mm:ss form, as a specific time of day.  In either case, the timeout interval
  38. must be within 12 hours of the present to avoid it being considered as  in  the
  39. past (expired).
  40.  
  41.  
  42. The CLEAR Command
  43.  
  44. Syntax: CLEAR
  45.  
  46. The  CLEAR command empties the buffers of the serial port to forget any earlier
  47. material.  This gets the INPUT command off to a clean start.  (This command was
  48. called  CLRINP  in 2.29B and earlier, and CLEAR was used to erase macro and key
  49. definition memory).
  50.  
  51.  
  52. The ECHO Command
  53.  
  54. Syntax: Echo text
  55.  
  56. The ECHO command is useful for reporting progress of a script, or prompting the
  57. user  for  interactive input.  The text is displayed on the screen, and may in-
  58. clude backslash notation for control or 8-bit characters.  An implied  linefeed
  59. is included at the beginning of the text.
  60.  
  61.  
  62. SET INPUT
  63.  
  64. Syntax: SET INPUT {CASE, DEFAULT-TIMEOUT, ECHO, TIMEOUT-ACTION}
  65.  
  66. The SET INPUT command controls the behavior of the script INPUT command:
  67.  
  68. SET INPUT CASE {IGNORE, OBSERVE}
  69.     Says whether or not to distinguish upper and lower case letters when  doing
  70.     a  matchup  in the INPUT command.  OBSERVE causes upper and lower case let-
  71.     ters to be distinguished.  The default is to IGNORE case distinctions.
  72.  
  73. SET INPUT DEFAULT-TIMEOUT seconds
  74.     Changes  the  default  waiting time from one second to this new value.  The
  75.     value is used when an INPUT command has no timeout specified.
  76.  
  77. SET INPUT ECHO {ON, OFF}
  78.     Show  on  the screen characters read from the serial port during the script
  79.     operation, or not.  Default is ON, show them.
  80.  
  81. SET INPUT TIMEOUT-ACTION {PROCEED, QUIT}
  82.     Determines  whether  or not the current macro or TAKE command file is to be
  83.     continued or exited if a timeout occurs.  PROCEED is the default and  means
  84.     that  timeouts  are  ignored.    QUIT  causes the current script file to be
  85.     exited and control passed to either the next higher level script  file  (if
  86.     there is one) or to Kermit's main prompt.
  87.  
  88. The SHOW SCRIPTS command displays the SET INPUT values.
  89.  
  90.  
  91. The INPUT command
  92.  
  93. Syntax: INPUT [timeout] {search-string, @filespec}
  94.  
  95. INPUT  is  the  most powerful of the script commands.  It reads characters from
  96. the serial port continuously until one  of  two  things  occurs:  the  received
  97. characters match the search string or the time limit expires.  Matching strings
  98. is the normal use, as in:
  99.  
  100.     Kermit-MS>input 5 Login please:
  101.  
  102. to recognize the phrase "Login please:", or else time out after  trying  for  5
  103. seconds.   A special binary character \255 or \o377 or \xFF stands for the com-
  104. bination carriage return and a line feed, in either order, to simplify  pattern
  105. matching.  The command reports a testable status of SUCCESS or FAILURE and sets
  106. the DOS ERRORLEVEL parameter to 2 if it fails to match within the  timeout  in-
  107. terval.    Characters  are stored in a 128 byte buffer for later examination by
  108. REINPUT, discussed below.
  109.  
  110. Beware of characters arriving with parity set because the pattern matching con-
  111. siders  all 8 bits of a byte unless the local parity is other than NONE and SET
  112. DISPLAY is 7-BITS.  Arriving characters are  modified  by  first  removing  the
  113. parity  bit, if parity is other than NONE, then they are passed through the SET
  114. TRANSLATION INPUT converter, the high bit is again suppressed if SET DISPLAY is
  115. 7-BITs, the result is logged and stored for pattern matching.
  116.  
  117.  
  118. The REINPUT command
  119.  
  120. Syntax: REINPUT [timeout] {search-string, @filespec}
  121.  
  122. The  REINPUT command is like INPUT except that characters are read from the 128
  123. byte serial port history buffer rather than always seeking fresh input from the
  124. port.    The purpose is to permit the current text to be examined several times,
  125. looking for different match strings.  A common case is reading the results of a
  126. connection  message  from  a  modem  which  might be "CONNECT 1200" or "CONNECT
  127. 2400", depending on the other modem.  If the history buffer has less  than  128
  128. bytes then fresh input may be requested while seeking a match, until the buffer
  129. is full.  REINPUT match searches begin at the start of the buffer whereas INPUT
  130. searches  never  go  back  over examined characters.  REINPUT sets the testable
  131. status of SUCCESS or FAILURE and DOS ERRORLEVEL, just as for INPUT.
  132.  
  133. The INPUT, REINPUT, and OUTPUT commands have a special syntax  to  replace  the
  134. normal string with text obtained from a file or device:
  135.  
  136.     OUTPUT @filespec
  137.     INPUT @filespec
  138.  
  139. Both  forms  read  one  line  of text from the file or device and use it as the
  140. desired string.  A common use is to wait for a password prompt  and  then  read
  141. the  password  from  the  console  keyboard.    A  string starts with the first
  142. non-spacing character and ends at either the end of line or, if executed within
  143. a  TAKE file, at a semicolon.  Indirectly obtained strings, the @filespec form,
  144. read the first line of the file up to but not including the  explicit  carriage
  145. return.    Note  if  a  trailing carriage return is needed it must be expressed
  146. numerically, such as \13 decimal.  Example:
  147.  
  148.     input 7 Password:
  149.     echo Please type your password:
  150.     output @con
  151.     output \13
  152.     echo \13\10Thank you!
  153.  
  154. In this example, a TAKE file requests the user to type in the  password  inter-
  155. actively,  so  that  it  does not have to be stored on disk as part of the TAKE
  156. file.
  157.  
  158. When a script fails because an INPUT or REINPUT command did not  encounter  the
  159. desired string within the timeout interval the message "?Timeout" is displayed.
  160.  
  161.  
  162. The OUTPUT command
  163.  
  164. Syntax: OUTPUT {string, @filespec}
  165.  
  166. The  OUTPUT command writes the indicated character string to the serial port as
  167. ordinary text.  The string may contain control or other special binary  charac-
  168. ters  by  representing  them  in backslash form.  Carriage Return (CR), for ex-
  169. ample, is \13 decimal, \o15 octal, or \x0D hexadecimal.   The  string  may  use
  170. 8-bit characters if the communications parity is type NONE.  A special notation
  171. is also provided, \b or \B, which causes a BREAK signal to be transmitted.
  172.  
  173. The string to be transmitted starts with the first non-spacing character  after
  174. the  OUTPUT command and ends at either the end of line or, if executed within a
  175. TAKE file, at a semicolon (if you need to output a semicolon from within a TAKE
  176. file,  use  backslash  notation, e.g. "\59").  Indirectly obtained strings, the
  177. @filespec form, read the first line of the file up to but not including the ex-
  178. plicit carriage return.
  179.  
  180. As a convenience, text arriving at the serial port during the OUTPUT command is
  181. shown on the screen if SET INPUT-ECHO is ON, and stored in a 128-byte  internal
  182. buffer for rereading by subsequent (RE)INPUT commands.
  183.  
  184.  
  185. The PAUSE command
  186.  
  187. Syntax: PAUSE [{number, hh:mm:ss}]
  188.  
  189. PAUSE  simply  waits one or more seconds before Kermit executes the next script
  190. command.  Pauses are frequently necessary to avoid overdriving the host and  to
  191. let  a modem proceed through a dialing sequence without interruptions from Ker-
  192. mit.  The default waiting time is set by SET INPUT DEFAULT-TIMEOUT and is  nor-
  193. mally one second.  The optional integer number selects the number of seconds to
  194. pause for this command, or a specific time of day.  An explicit value  of  zero
  195. produces  a pause of just a few milliseconds which can be useful in some situa-
  196. tions.
  197.  
  198. Text arriving during the  PAUSE  interval  is  shown  on  the  screen,  if  SET
  199. INPUT-ECHO  is  ON, and stored in a 128-byte internal buffer for rereading by a
  200. following INPUT command.
  201.  
  202. PAUSE is interrupted if there is any activity on the keyboard.  Thus PAUSE  can
  203. be useful for operations like:
  204.  
  205.     echo "Type any key when ready..."
  206.     pause 9999
  207.  
  208.  
  209. The WAIT Command
  210.  
  211. Syntax: WAIT [{number, hh:mm:ss}] [\CD] [\CTS] [\DSR]
  212.  
  213. WAIT  performs  a  timed  PAUSE, as above, but also examines the optional modem
  214. control signals Carrier Detect (\CD),  Clear  To  Send  (\CTS),  and  Data  Set
  215. (modem)  Ready (\DSR).  If all of the specified signals is ON, or become ON be-
  216. fore the timeout interval, the wait operation ceases with an indication of SUC-
  217. CESS.     If  the time interval expires without all of the specified signals on,
  218. the status is FAILURE.  Example:
  219.  
  220.     Kermit-MS> WAIT 12:45 \cd \dsr
  221.  
  222. This waits until 45 minutes past noon for both CD and DSR to  be  asserted,  or
  223. fails.
  224.  
  225. If no modem signals are specified, then WAIT is the same as PAUSE.
  226.  
  227.  
  228. Labels and the GOTO Command
  229.  
  230. Labels  and  the GOTO command work together in the same fashion as in DOS Batch
  231. files.  A label is a line which starts with a colon (:) in the leftmost  column
  232. followed immediately by a word of text (no intervening spaces); material on the
  233. line after the label is ignored.  The GOTO command is followed by a label,  the
  234. leading colon is optional in the GOTO command.  The label may be located either
  235. before or after the GOTO command and is found by searching  the  TAKE  file  or
  236. macro  from  the  beginning.  Thus, duplicated labels will always use the first
  237. occurrence.  The target label must be in the current TAKE file  or  macro;  one
  238. may not GOTO a label in another TAKE file or macro.  Example:
  239.  
  240.     :LOOP
  241.     echo again and\13
  242.     goto loop
  243.  
  244. will  print "again and again and again and..." forever (until you type Ctrl-C).
  245. As a macro:
  246.  
  247.     define test :loop,echo again and\13,goto loop
  248.     do test
  249.  
  250. Note that if a label follows a comma in a macro definition, there  must  be  no
  251. intervening spaces:
  252.  
  253.     define test ..., :top, ..., goto top  ; bad, space before colon.
  254.     define best ...,:top, ..., goto top   ; good, no space.
  255.  
  256. In this example, the best macro will work, the test macro won't.
  257.  
  258.  
  259. The IF Command
  260.  
  261. Syntax: IF test-condition MS-Kermit Command
  262.  
  263. The  IF  command  gives  MS-Kermit scripts the ability to make a decision based
  264. upon the criterion specified as the test-condition.  If the test  condition  is
  265. true,  then  the command is executed.  Otherwise, it is skipped.  The test con-
  266. ditions are:
  267.  
  268.     NOT     Modifier for other conditions below.
  269.  
  270.     ALARM   True if the current time of day is at or later than the alarm clock
  271.         time.    The alarm clock time is set by the command SET ALARM time.
  272.         IF ALARM distinguishes early from late with  a  12  hour  field  of
  273.         view.
  274.  
  275.     COUNT   True  if the current COUNT variable is greater than zero.  COUNT is
  276.         a special Kermit variable for each active TAKE file or macro.    It
  277.         is  set by the command SET COUNT and it is both tested and modified
  278.         by the IF COUNT command.  The intent is to construct simple  script
  279.         loops  where the IF COUNT command first decreases COUNT by one (but
  280.         never below zero) and then if COUNT is greater than zero  the  fol-
  281.         lowing  Kermit  command is executed.  Because COUNT exists only for
  282.         TAKE files and macros it cannot be used interactively.   Each  TAKE
  283.         file  or  macro has its own distinct copy of COUNT, and nested TAKE
  284.         files or macros do not interact through their  COUNTs.    Initially
  285.         COUNT is zero.
  286.  
  287.     DEFINED symbol
  288.         True if the named macro or variable is defined.  You can  use  this
  289.         feature to remember things for future reference.
  290.  
  291.     ERRORLEVEL number
  292.         True if the DOS errorlevel number  matches  or  exceeds  the  given
  293.         (decimal) number.
  294.  
  295.     EXIST filespec
  296.         True if the specified file exists.
  297.  
  298.     FAILURE True if  the  previous  status-returning  Kermit  command  reported
  299.         failure.
  300.  
  301.     SUCCESS True  if the previous status-returning Kermit command reported suc-
  302.         cess.  When using IF SUCCESS and IF FAILURE, it is important to SET
  303.         INPUT  TIMEOUT  PROCEED, otherwise the script will quit immediately
  304.         upon a failing INPUT or REINPUT, before getting to  the  IF  state-
  305.         ment.
  306.  
  307. IF  commands  are closely modeled on those of DOS Batch files, for familiarity.
  308. They consist of a test condition, perhaps modified by the leading word NOT, and
  309. then  any  legal  Kermit command.  GOTO is an especially useful command here to
  310. branch in the TAKE file or macro.
  311.  
  312. The "object" of an IF command is a Kermit command, which can be:
  313.  
  314.    - A regular, predefined Kermit command, like SEND FOO.BAR or SET  SPEED
  315.      1200.
  316.  
  317.    - A GOTO, allowing subsequent statements to be skipped.
  318.  
  319.    - Another  IF  command,  as  in  IF  DEFINED  \%3 IF EXIST FOO.BAR SEND
  320.      FOO.BAR.  The SEND command is executed only if both IF conditions are
  321.      true.
  322.  
  323.    - A  macro.  This allows a semblence of structured programming, with an
  324.      implied "begin" and "end" around the commands that compose the macro.
  325.      For instance:
  326.  
  327.      define giveup echo I give up!, hangup, stop
  328.      input 10 Login:
  329.      if failure giveup
  330.      output myusername
  331.  
  332. The  Kermit  commands which yield SUCCESS or FAILURE conditions are: GET, SEND,
  333. RECEIVE, the REMOTE commands, INPUT, REINPUT, BYE, FINISH, LOGOUT, and WAIT.
  334.  
  335.  
  336. Script Examples
  337.  
  338. A counting loop.  This TAKE file excerpt says  hello  three  times,  then  says
  339. goodbye:
  340.  
  341.     set count 3            ; Prime the loop counter for three passes
  342.     :TOP            ; A label for GOTO
  343.     echo Hello\13        ; Something to see, with carriage return
  344.     if count goto top        ; Loop if COUNT is greater than zero
  345.     echo Goodbye!\13
  346.  
  347. Figure 1-2 shows a simple script file that logs in to a computer, prompting the
  348. user for her password using the @con construction, and then connects as a  ter-
  349. minal.
  350.  
  351. -------------------------------------------------------------------------------
  352.  
  353.  
  354.     define ermsg echo %\1\13, stop     ; Define an error handling macro.
  355.     clear                 ; Clear the input buffer.
  356.     set speed 9600             ; Set the transmission speed.
  357.     output \13                 ; Carriage return to awaken host.
  358.     input 15 Login:             ; Wait up to 15 secs for prompt.
  359.     if failure ermsg No login prompt!     ; Give up if none.
  360.     output Sari\13             ; Send username and CR.
  361.     set input echo off             ; Privacy, please.
  362.     input 5 Password:             ; Quietly wait for this.
  363.     if failure ermsg No password prompt! ; Give up if it doesn't come.
  364.     echo Type your password now...     ; Make our own prompt.
  365.     output @CON                 ; Send console keystrokes.
  366.     output \13                 ; Add a real carriage return.
  367.     input 30 $                 ; Wait for system prompt.
  368.     if failure ermsg No system prompt!   ; Give up if none.
  369.     connect                 ; Start terminal emulation.
  370.  
  371.          Figure 1-2:   MS-Kermit Script for Logging In
  372.  
  373. -------------------------------------------------------------------------------
  374.  
  375. Notice  the  semicolons used to indicate comments in TAKE files.  If these same
  376. commands were typed by hand at the Kermit prompt the semicolon  material  would
  377. be  considered  part  of  a string!  Typing a Control-C will interrupt and ter-
  378. minate any of the commands.
  379.  
  380. Figure 1-3 illustrates some detailed control of the Hayes modem.   Some  under-
  381. standing  of  the Hayes dialing language is helpful for deciphering this script
  382. (consult your Hayes modem manual).  If the script is stored in  a  file  called
  383. HAYES.SCR, then a DIAL macro can be defined like this:
  384.  
  385.     define dial take hayes.scr
  386.  
  387. The  trick  here is that any invocation of the "dial" or "do dial" command with
  388. an operand will set the variable \%1, which is used in the TAKE file,  for  in-
  389. stance:
  390.  
  391.     dial 765-4321
  392.  
  393. will set \%1 to "765-4321", the number to be dialed.
  394.  
  395. -------------------------------------------------------------------------------
  396.  
  397.  
  398.     if defined %\1 goto start         ; Make sure number specified.
  399.     echo Please supply a phone number!\13
  400.     stop
  401.     :START
  402.     clear                 ; Clear the input buffer.
  403.     set speed 2400             ; Dial at high speed.
  404.     wait 10 \dsr             ; Is modem turned on?
  405.     if success goto init
  406.     echo Please turn on your modem.\13   ; It's not, complain,
  407.     stop                 ; and exit the script.
  408.     :INIT
  409.     echo Initializing modem...\13\10     ; Modem is turned on.
  410.     output ATZ F1 Q0 V1 X4 S0=0\13     ; Initialize the modem.
  411.     input 5 OK                 ; Get its response.
  412.     if success goto dial         ; If OK, go ahead and dial
  413.     echo Can't initialize the modem!\13  ; Not OK, give up.
  414.     stop
  415.     :DIAL                 ; Ready to dial.
  416.     set count 5                 ; Set the redial limit.
  417.     define \%d \13Dialing         ; Initial dial message.
  418.     :REDIAL
  419.     echo \%d \%1...\13             ; Tell them we're dialing.
  420.     output ATDT \%1\13             ; Dial the phone number.
  421.     clear                 ; Clear away the command echo.
  422.     input 30 CONNECT             ; Wait for CONNECT message.
  423.     if success goto speed         ; Got it, go check speed.
  424.     define \%m No dialtone or no answer. ; Make this the error message.
  425.     reinput BUSY             ; Didn't connect.  Was it busy?
  426.     if failure goto later         ; No, something else.
  427.     Echo \13Busy...             ; It's busy, let them know.
  428.     pause 60                 ; Wait one minute.
  429.     define \%d \13Redialing         ; Change message to "Redialing".
  430.     if count goto redial         ; Then go redial.
  431.     define \%m \13Line busy.         ; After 5 tries set this message.
  432.     :LATER                 ; Get here upon giving up.
  433.     echo \%m\10\13Try again later.\13     ; Issue error message.
  434.     stop                 ; Exit from the script.
  435.     :SPEED                 ; Connected!
  436.     pause 1                 ; Wait for text after CONNECT.
  437.     define \%s 2400             ; Assume speed is 2400.
  438.     reinput 1 2400             ; Rescan current text for "2400"
  439.     if success goto done         ; It is.
  440.     define \%s 1200             ; It isn't, so assume 1200.
  441.     reinput 1 1200             ; Is it?
  442.     if failure define \%s 300         ; It isn't, so it must be 300.
  443.     :DONE                 ; We know the speed.
  444.     set speed \%s             ; So set it.
  445.     echo Connecting at \%s bps...\13     ; Tell the user.
  446.     connect                 ; And start terminal emulation.
  447.  
  448.    Figure 1-3:   MS-Kermit Script for More Control of a Hayes 2400 bps Modem
  449.  
  450. -------------------------------------------------------------------------------
  451.  
  452. A  combination of DOS Batch and Kermit Script files is shown in Figures 1-4 and
  453. 1-5 (see your DOS manual for an explanation of the batch  file  syntax).    The
  454. purpose  is  to allow a user to say "SEND filename" at the DOS prompt.  The DOS
  455. batch shell, SEND.BAT, and the login script, KX, are combined to login to a VAX
  456. through a data switch, run VMS Kermit in server mode, transfer the file, submit
  457. it to VMS Mail, delete the disk file, shut down the server and logout from  the
  458. VAX,  and  report  the overall transfer status.  The user is asked to provide a
  459. password interactively.
  460.