123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #!/usr/bin/expect --
- if { [llength $argv] < 4 } {
- puts "Usage: $argv0 ip user passwd port commands timeout"
- exit 1
- }
- match_max 600000
- set ipcode [lindex $argv 0]
- set ip [exec dc -e $ipcode]
- set user [lindex $argv 1]
- set passwdcode [lindex $argv 2]
- set passwd [exec dc -e $passwdcode]
- set portcode [lindex $argv 3]
- set port [exec dc -e $portcode]
- set commands [lindex $argv 4]
- set timeoutflag [lindex $argv 5]
- set yesnoflag 0
- set timeout $timeoutflag
- for {} {1} {} {
- # for is only used to retry when "Interrupted system call" occured
- spawn /usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port $ip
- expect {
- "assword:" {
- send "$passwd\r"
- break;
- }
- "yes/no)?" {
- set yesnoflag 1
- send "yes\r"
- break;
- }
- "FATAL" {
- puts "\nCONNECTERROR: $ip occur FATAL ERROR!!!\n"
- exit 1
- }
- timeout {
- puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
- exit 1
- }
- "No route to host" {
- puts "\nCONNECTERROR: $ip No route to host!!!\n"
- exit 1
- }
- "Connection Refused" {
- puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
- exit 1
- }
- "Connection refused" {
- puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
- exit 1
- }
- "Host key verification failed" {
- puts "\nCONNECTERROR: $ip Host key verification failed!!!\n"
- exit 1
- }
- "Illegal host key" {
- puts "\nCONNECTERROR: $ip Illegal host key!!!\n"
- exit 1
- }
- "Connection Timed Out" {
- puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
- exit 1
- }
- "Interrupted system call" {
- puts "\n$ip Interrupted system call!!!\n"
- }
- }
- }
- if { $yesnoflag == 1 } {
- expect {
- "assword:" {
- send "$passwd\r"
- }
- "yes/no" {
- set yesnoflag 2
- send "yes\r"
- }
- }
- }
- if { $yesnoflag == 2 } {
- expect {
- "assword:" {
- send "$passwd\r"
- }
- }
- }
- expect {
- "@" {send "$commands \r"}
- "assword:" {
- send "$passwd\r"
- puts "\nPASSWORDERROR: $ip Password error!!!\n"
- exit 1
- }
- }
- expect {
- "@" {send "sleep 1\r"}
- }
- expect {
- "@" {send "exit\r"}
- }
- expect eof {
- puts "OK_SSH: $ip\n"
- exit 0;
- }
|