This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: ssh expect on Cygwin
- From: Christopher Cobb <ccobb at email dot com>
- To: cygwin at cygwin dot com
- Date: Sat, 30 Oct 2004 21:05:19 +0000 (UTC)
- Subject: Re: ssh expect on Cygwin
- References: <ffec403e0410192007589447dc@mail.gmail.com>
anurag shukla <shuklaan <at> gmail.com> writes:
>
> I am having a tyical problem with expect.
Since passwordless authentication is broken on many cygwin systems I use, I end
up using the following expect script (more frequently that I would like). By
populating the user and passwd arrays for various hosts, this script can be used
to access arbitrary remote hosts.
--- remoteLogin ---
#!/usr/bin/expect -f
set user(myHostName) "Administrator"
set passwd(myHostName) "mySecretPassword"
log_user 0
set timeout -1
set host [file tail $::argv0]
if {[llength $argv] == 0} {
spawn ssh $user($host)@$host
} else {
spawn ssh $user($host)@$host [join [lrange $argv 0 end]]
}
match_max 100000
expect {
-re "ssh: connect to host .* port 22: Connection refused" {
send_user "Connection to port 22 on $host refused.\n"
exp_exit 1
}
-re "ssh: connect to host .* port 22: Connection timed out" {
send_user "Connection attempt to port 22 on $host timed out.\n"
exp_exit 1
}
-exact "Are you sure you want to continue connecting (yes/no)? " {
send "yes\r"
exp_continue
}
-exact " password: " { send -- "$passwd($host)\r" }
}
expect "\r" # eat the RETURN after entering the password
if {[llength $argv] == 0} { # interactive
expect {
-glob "Connection to * closed." {
send_user "Connection to $host has spontaneously closed.\n"
exp_exit 1
}
-exact "Permission denied, please try again." {
send_user "Password not accepted.\n"
exp_exit 1
}
-exact "\r" ;# continue if error not encountered
}
log_user 1
expect -re "(\\$|\>) "
interact { "\004" { close; wait; exit } }
} else { # non-interactive
log_user 1
expect eof
}
--- end remoteLogin ---
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/