Linux中如何自动处理交互?

可以使用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
"
原文地址:https://www.cnblogs.com/Richardo-M-Q/p/15049213.html