|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
各位大神,我近日在做一个expect脚本,需求如下:
ssh进入一台机器,然后在那台机器上运行ping来测试端口
Codes:
proc ssh {} {
global DST_IP
global PSWD
global PING_IP
spawn ssh $DST_IP
expect {
-re ".*password.*" {
send "$PSWD\r"
}
}
expect {
"Permission denied, please try again" {
puts "\033\[31m>>>>>>>>>>>Permission Denied, please double check your PASSWORD"
exit
}
-re ".*Last login" {
# interact
exec "hostname"
expect {
-ex "testbench" {
puts "\033\[32m>>>>>>>>>>>>>>Login Successfully!"
# ping
spawn ping $PING_IP -c 10
expect {
-re "\[\r\n]+.*10 packets transmitted" {
if { $expect_out(1,string) == "10" } {
puts "Ping is Fine!"
} else {
puts "Ping is failed!"
}
}
-re "\[\r\n].*Unreachable" {
puts "\033\[31m$PING_IP is Unreachable"
puts "\033\[30m\n"
}
}
exit
# exit
}
eof {
puts "\033\[31m>>>>>>>>>>>>>>>>Login Failed"
# exit
}
timeout {puts "No response!"}
}
}
eof {
puts "\033\[31m>>>>>>>>>>>>>>>>Login Failed"
}
timeout {puts "No response!"}
}
exit
}
红色部分总是在我当前机器上执行,而不是在我ssh进去的机器上执行,请问改如何实现?
谢谢! |
|