home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / autotelnet6 < prev    next >
Text File  |  2020-01-01  |  4KB  |  111 lines

  1. #!/usr/local/bin/kermit
  2.  
  3. ; Illustration of scripted Telnet login using C-Kermit 6.0
  4. ; Compare with the version for C-Kermit 7.0.
  5. ; (The main difference is the ease in passing parameters from the command line)
  6. ;
  7. ; Optional command-line parameters (must be preceded by "=" sign).
  8. ;  1. Hostname or address
  9. ;  2. Username on host
  10. ;  3. Password on host
  11. ;
  12. ; Example:
  13. ;  autotelnet6 = xyzcorp.com fred secret
  14. ;
  15. ; Parameters not supplied are prompted for.
  16. ; Uses Telnet port only since a login dialog is assumed.
  17. ; Write a different script for accessing non-Telnet ports.
  18. ;
  19. ; WARNING: This is just an illustration.  It works with most servers,
  20. ; but is not general enough to work with all.  Prompts might be different,
  21. ; some terminal-related escape sequences might need to be exchanged, etc.
  22. ; See Chapter 19 of "Using C-Kermit" for details.
  23. ;
  24. define badversion echo Sorry - C-Kermit 6.0 or later required., exit
  25. if not equal "\v(program)" "C-Kermit" badversion
  26. if LLT "\v(version)" "600192" badversion
  27.  
  28. local \%i \%h \%u \%p logging          ; Local variables
  29.  
  30. define logging 0                       ; Change to 1 to log the session
  31.  
  32. define fatal { if def \%1 echo \%1, exit 1 }
  33.  
  34. set network type tcp/ip
  35. if fail fatal {Sorry, this version of C-Kermit does not support TCP/IP.}
  36.  
  37. ; In C-Kermit versions prior to 7.0, we have to extract the arguments from
  38. ; the command line.
  39. ;
  40. for \%i 1 \v(args) 1 {
  41.     xif equal "\&@[\%i]" "=" {
  42.         incr \%i
  43.         if = \v(args) \%i break
  44.         asg \%h \&@[\%i]
  45.         incr \%i    
  46.         if = \v(args) \%i break
  47.         asg \%u \&@[\%i]
  48.         incr \%i
  49.         if = \v(args) \%i break
  50.         asg \%p \&@[\%i]
  51.         break
  52.     }
  53. }
  54. while not def \%h {                    ; If hostname/address not supplied
  55.     ask \%h { Host: }                  ; prompt for one until we get it.
  56.     xif > 0 \index(\32,\%h,1) 1 {      ; Allow only one "word" here.
  57.         echo Just the address please.  ; E.g. no TCP port number.
  58.         undef \%h
  59.     }
  60. }
  61. xif not def \%u {                      ; If username not supplied
  62.     ask \%u { User: }                  ; Prompt for one, but default
  63.     if not def \%u assign \%u \v(user) ; to local user ID.
  64. }
  65.  
  66. echo Connecting to \%h as user \%u...
  67.  
  68. set host \%h 23                        ; Connect on Telnet port
  69. if fail fatal {Can't open Telnet connection to \%h.}
  70.  
  71. if \m(logging) log session             ; Make session.log file
  72.  
  73. ; Prompt for password if necessary only after connection is made
  74. ; (because there's no point in asking for it if the connection failed).
  75.  
  76. while not defined \%p {
  77.     askq \%p { Password for \%u at \%h: }
  78. }
  79. set input echo off                     ; Don't echo scripted interactions.
  80.  
  81. ; Note that some Telnet servers get your user ID automatically in Telnet
  82. ; negotiations and so only prompt for Password:, so look for both at once.
  83. ; Also allow username prompt to be "login:" (UNIX) or "Username:" (VMS).
  84. ; Also allow for the fact that some servers prompt "Password for blah:",
  85. ; whereas most others prompt just "Password:".
  86.  
  87. minput 20 login: Username: Password: {Password for \%u:}
  88. if fail fatal {Timed out waiting for initial prompt}
  89. xif < \v(minput) 3 {
  90.     output \%u\13                      ; User ID required - send it.
  91.     minput 10 Password: {Password for \%u:}
  92.     if fail fatal {Timed out waiting for Password prompt}
  93. }
  94. output \%p\13                          ; Send password
  95. undef \%p                              ; Erase password from memory
  96. set exit on-disconnect on              ; Exit automatically if connection lost.
  97.  
  98. ; The CONNECT command sends you online for an interactive session.  Instead
  99. ; of CONNECT, you can substitute additional scripting for automation of any
  100. ; interactions you would do by hand: use INPUT, OUTPUT, IF FAIL (or IF
  101. ; SUCCESS), and other scripting commands for this.  In a common example,
  102. ; you can start a Kermit server on the remote end and then transfer and/or
  103. ; manage remote files from this script.
  104.  
  105. connect
  106.  
  107. ; At this point, escaping back while the connection is open will give you
  108. ; the C-Kermit> command prompt unless you include additional commands below.
  109.  
  110. End ; of C-Kermit sample Telnet script.
  111.