- 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
|
#!/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
|
;; 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:
|
;; TODO:
|
||||||
;; - detect if the arguments for ssh do not cause a log in, like --help ?
|
;; - 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
|
(define *connect-timeout* 5)
|
||||||
;; wait for a prompt, since we don't know how it will look like.
|
(define *prompt-timeout* 3)
|
||||||
(define *time-until-prompt* 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)
|
(define (main args)
|
||||||
(let ((dir (cwd))
|
(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))
|
(user-in (current-input-port))
|
||||||
(task (spawn (ssh . ,(cdr args)))))
|
(task (spawn (ssh . ,(cdr args)))))
|
||||||
(chat task
|
(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))
|
(let lp ((first? #t))
|
||||||
|
(chat-timeout (if first?
|
||||||
|
*connect-timeout*
|
||||||
|
*prompt-timeout*))
|
||||||
(look-for "Password:")
|
(look-for "Password:")
|
||||||
(if (not first?)
|
(if (not first?)
|
||||||
(display "Incorrect password. Try again.\n" user-out))
|
(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)))
|
user-in user-out)))
|
||||||
(send/cr pw)
|
(send/cr pw)
|
||||||
(lp #f))))
|
(lp #f))))
|
||||||
(sleep *time-until-prompt*)
|
|
||||||
(tsend/cr task (string-append "cd " dir))
|
(tsend/cr task (string-append "cd " dir))
|
||||||
(run (stty -echo raw)) ;; TODO: do this interally
|
|
||||||
(interact task)
|
(let ((tty-before (tty-info user-in)))
|
||||||
(run (stty echo -raw))))
|
(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
|
;; read string without echoing it
|
||||||
;; optionals arguments:
|
;; optionals arguments:
|
||||||
|
|
Loading…
Reference in New Issue