expect使用demo

#!/usr/bin/expect
set timeout 30
set ip [lindex $argv 0]
spawn ssh root@$ip
 
expect {
"yes/no" { send "yes
"; exp_continue }
"password:" { send "123456
" }
}

expect "#"
send "sed -e '1,1000s/dns-search/#dns-search/' /etc/network/interfaces > /etc/network/test 
"

expect "#"
send "mv -f /etc/network/test /etc/network/interfaces 
"

expect "#"
send "/etc/init.d/networking restart 
"
 
expect "#"
send "exit
"
原文地址:https://www.cnblogs.com/sayaoailun/p/4708763.html