編輯:沒有條件,一切正常工作。在條件中添加可以打破腳本。我試過其他更簡單的腳本中的條件和那些工作。期望條件似乎沒有工作
EDIT2:添加完整的腳本的其他實例想到條件句工作過
我試圖修改autoexpect產生期望腳本時生成成功,但不處理構建失敗的作品。
顯著的研究後,我想不通爲什麼我的期望條件是不工作
#!/usr/bin/expect -f
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set timeout -1
spawn $env(SHELL)
match_max 100000
expect "~\$ "
send -- "sudo su\r"
expect "/home/ubuntu# "
send -- "cd ../../opt/application/"
send -- "\r"
expect "/opt/application# "
send -- "./buildwar.sh \r"
expect {
"BUILD SUCCESSFUL\r" {
send -- "su appuser\r"
expect "/opt/application\$ "
send -- "../../home/ubuntu/shutdown.sh \r"
expect "\"outcome\" => \"success\"}"
send -- "exit\r"
expect "/opt/application# "
send -- "./deploywar.sh \r"
expect "BUILD SUCCESSFUL"
send -- "su appuser\r"
expect "/opt/application\$ "
send -- "../../home/ubuntu/startup.sh \r"
expect "Deployed \"application.war\""
send -- "exit\r"
send -- "exit\r"
send -- "exit\r"
exit 0
}
"BUILD FAILED\r" {
exit 1
}
}
你成功退出1? – chrisaycock
@chrisaycock是的 - 這種方式調用這個期望腳本的shell腳本可以繼續它的其他職責 –
@General_Twyckenham:壓力是在'1'上。爲什麼你返回一個錯誤? –