- using scsh's tty functions
- wait for a prompt regexp, with a timeout if it does not match - print out the things that chat consumed (e.g. a login-message)
This commit is contained in:
parent
dd1583ad55
commit
87fd5ead30
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh
|
||||
exec scsh -lel expect/load.scm -o threads -o chat -o expect -o let-opt -e main -s "$0" "$@"
|
||||
exec scsh -lel expect/load.scm -o threads -o chat -o tty-utils -o expect -o let-opt -e main -s "$0" "$@"
|
||||
!#
|
||||
|
||||
;; this script runs the SSH program and passes all it's arguments to
|
||||
|
@ -11,10 +11,17 @@ exec scsh -lel expect/load.scm -o threads -o chat -o expect -o let-opt -e main -
|
|||
|
||||
;; TODO:
|
||||
;; - detect if the arguments for ssh do not cause a log in, like --help ?
|
||||
;; - detect if machine does not answer
|
||||
|
||||
;; time to wait after logged in until we enter commands - we cannot
|
||||
;; wait for a prompt, since we don't know how it will look like.
|
||||
(define *time-until-prompt* 3)
|
||||
(define *connect-timeout* 5)
|
||||
(define *prompt-timeout* 3)
|
||||
|
||||
(define *prompt-regexp*
|
||||
(let ((env (getenv "PROMPT_REGEXP")))
|
||||
(or env
|
||||
(rx (+ ,(char-set-difference char-set:full
|
||||
(string->char-set " ")))
|
||||
"[" (* any) "] "))))
|
||||
|
||||
(define (main args)
|
||||
(let ((dir (cwd))
|
||||
|
@ -22,8 +29,21 @@ exec scsh -lel expect/load.scm -o threads -o chat -o expect -o let-opt -e main -
|
|||
(user-in (current-input-port))
|
||||
(task (spawn (ssh . ,(cdr args)))))
|
||||
(chat task
|
||||
(chat-abort "Last login:")
|
||||
(chat-monitor (lambda (ev msg)
|
||||
(cond
|
||||
((eq? ev 'abort)
|
||||
(write-string (task:pre-match task) user-out)
|
||||
(write-string msg user-out)
|
||||
(write-string (task:buf task) user-out))
|
||||
((eq? ev 'timeout)
|
||||
(write-string (task:pre-match task) user-out)
|
||||
(write-string (task:buf task) user-out)))))
|
||||
(chat-abort *prompt-regexp*)
|
||||
|
||||
(let lp ((first? #t))
|
||||
(chat-timeout (if first?
|
||||
*connect-timeout*
|
||||
*prompt-timeout*))
|
||||
(look-for "Password:")
|
||||
(if (not first?)
|
||||
(display "Incorrect password. Try again.\n" user-out))
|
||||
|
@ -31,11 +51,16 @@ exec scsh -lel expect/load.scm -o threads -o chat -o expect -o let-opt -e main -
|
|||
user-in user-out)))
|
||||
(send/cr pw)
|
||||
(lp #f))))
|
||||
(sleep *time-until-prompt*)
|
||||
|
||||
(tsend/cr task (string-append "cd " dir))
|
||||
(run (stty -echo raw)) ;; TODO: do this interally
|
||||
(interact task)
|
||||
(run (stty echo -raw))))
|
||||
|
||||
(let ((tty-before (tty-info user-in)))
|
||||
(modify-tty (lambda (ti) (raw (echo-off ti))) user-in)
|
||||
;; raw-initialize needed??
|
||||
|
||||
(interact task)
|
||||
|
||||
(set-tty-info/now user-in tty-before))))
|
||||
|
||||
;; read string without echoing it
|
||||
;; optionals arguments:
|
||||
|
|
Loading…
Reference in New Issue