可以使用except脚本和shell脚本结合起来使用。
#!/usr/bin/expect -f
set ip [ lindex $argv 0 ]
set username [ lindex $argv 1 ]
set passwd [ lindex $argv 2 ]
set interface [ lindex $argv 3]
set timeout 10
spawn ssh $username@$ip
expect {
"(yes/no)" { send "yes
"; exp_continue }
"*assword*" { send "$passwd
" }
}
expect ">";
send "return
"
send "save
"
sleep 30
send "y
"
send "system
"
send "interface $interface
"
send "shutdown
"
send "commit
"
send "undo shutdown
"
send "commit
"
send "shutdown
"
send "commit
"
send "undo shutdown
"
send "commit
"
send "shutdown
"
send "commit
"
send "undo shutdown
"
send "commit
"
send "shutdown
"
send "commit
"
send "undo shutdown
"
send "commit
"
send "shutdown
"
send "commit
"
send "undo shutdown
"
send "commit
"
send "quit
"
send "quit
"
send "quit
"