| delorie.com/archives/browse.cgi | search |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
| To: | cygwin AT cygwin DOT com |
| From: | Christopher Cobb <ccobb AT email DOT com> |
| Subject: | Re: ssh expect on Cygwin |
| Date: | Sat, 30 Oct 2004 21:05:19 +0000 (UTC) |
| Lines: | 62 |
| Message-ID: | <loom.20041030T225458-100@post.gmane.org> |
| References: | <ffec403e0410192007589447dc AT mail DOT gmail DOT com> |
| Mime-Version: | 1.0 |
| X-Complaints-To: | usenet AT sea DOT gmane DOT org |
| X-Gmane-NNTP-Posting-Host: | main.gmane.org |
| User-Agent: | Loom/3.14 (http://gmane.org/) |
| X-Loom-IP: | 162.70.244.40 (Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.8) |
| X-IsSubscribed: | yes |
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/
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |