0
我想重新啓動系統使用expect。這裏是我的代碼:如何在預期返回到以前的腳本
#!/usr/bin/expect
set timeout 20
set name [lindex $arg0]
set user [lindex $arg1]
set password [lindex $arg2]
spawn telnet $name
expect "login:"
send "$user\n"
expect "Password:"
send "$password\n"
expect "<system prompt>$"
send "<some command>\n"
expect "<system prompt>$"
send "./my_script\n" --> code is below
send "<back to the telnet system prompt and running a builtin command>"
expect "g>"
send "some built in command"
這裏是my_script(我重新引導系統,在此之後,連接丟失和上面的腳本(主腳本)的線端)的代碼
#!/usr/bin/expect
set name [lindex <some ip>]
set user [lindex <name>]
set password [lindex <password>]
spawn telnet $name
expect "Login:"
send "$user\n"
expect "Password:"
send "$password\n"
expect "<system prompt>"
send "reboot\n"
expect "Are you sure you want to reboot (y/n)?"
send "y"
在這裏,它失去了連接,並且永遠不會返回到主腳本,並繼續執行腳本的其餘部分。
注意:如果我在兩個腳本的末尾都進行了交互,但我不想進行交互,因爲我們不需要用戶提供任何內容。
您的內置命令執行沒有發生在主腳本中提到? – Dinesh