linux expect

先安装如下软件
yum install -y expect*
yum install -y tcl*

example
#!/usr/bin/expect -f

set ipaddr "172.16.3.3"

set passwd "taovo@123"

spawn ssh taovo@$ipaddr             

expect {

"yes/no" { send "yes\r"; exp_continue}

"password:" { send "$passwd\r" }

}

expect "]#"

send "touch a.txt\r"                     

send "exit\r"

expect eof

exit

你可能感兴趣的:(linux expect)