- 论坛徽章:
- 0
|
看下我的
#!/usr/bin/expect -f
set USER [lindex $argv 0]
set HOST [lindex $argv 1]
set PASSWD [lindex $argv 2]
spawn ssh -l $USER $HOST
set timeout 60
while {1} {
expect -re "Are you sure you want to continue connecting (yes/no)?" {
# First connect, no public key in ~/.ssh/known_hosts
send "yes\r"
} -re "assword:" {
# Already has public key in ~/.ssh/known_hosts
send "$PASSWD\r"
} -re "Permission denied, please try again." {
# Password not correct
exit 1
} -re "Connection refused" {
exit 1
} timeout {
exit 1
} "#" {
interact
} "losed" {
exit 1
}
} |
|