forked from oneinstack/oneinstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmssh.exp
executable file
·129 lines (103 loc) · 2.13 KB
/
mssh.exp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/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;
}