先安装如下软件
example
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