1
爲什麼這個期望的腳本不斷產生ssh命令,從不打印「進入睡眠」或者「離開睡眠」,並且從不睡覺?爲什麼不這樣期待句柄超時或者eof
我的意圖是嘗試ssh'ing,如果它看到「password:」以退出while循環(更多代碼在這裏看不到會包含交互)。如果3秒鐘過去,或ssh在此之前死亡,它會應該放3秒睡,再放,然後再試ssh。
主機名「doesntexist」用於強制失敗,例如名稱或服務未知。
#!/usr/bin/expect -f
set readyForPassword 0
while { $readyForPassword == 0 } {
spawn ssh [email protected]
expect -timeout 3 {
"password: " {
set readyForPassword 1
} timeout {
puts "going to sleep"
sleep 3
puts "out of sleep"
} eof {
puts "going to sleep"
sleep 3
puts "out of sleep"
}
}
}
呵呵。如果我刪除了{在期望行結束時(及其底部附近的大括號)並使期望行爲'expect -timeout 3「密碼:」{「然後它按預期工作。探索Expect說,你可以按照我原來的方式來支撐它,至少在p76我想。期望改變嗎?我誤解別的東西了嗎? – user1902689