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\r"; exp_continue }
    "*assword*" { send "$passwd\r" }
       }
expect ">";
send "return\r"
send "save\r"
sleep 30
send "y\r"
send "system\r"
send "interface $interface\r"
send "shutdown\r"
send "commit\r"
send "undo shutdown\r"
send "commit\r"
send "shutdown\r"
send "commit\r"
send "undo shutdown\r"
send "commit\r"
send "shutdown\r"
send "commit\r"
send "undo shutdown\r"
send "commit\r"
send "shutdown\r"
send "commit\r"
send "undo shutdown\r"
send "commit\r"
send "shutdown\r"
send "commit\r"
send "undo shutdown\r"
send "commit\r"
send "quit\r"
send "quit\r"
send "quit\r"
posted @ 2021-07-23 15:55  Richardo-M-Lu  阅读(84)  评论(0编辑  收藏  举报