Linux-expect脚本-编写一个expect脚本
1.声明expect #!/usr/bin/expect -f
2.设置超时时间,获取参数
set ip [lindex $argv 0 ] //接收第一个参数,并设置IP
set password [lindex $argv 1 ] //接收第二个参数,并设置密码
set timeout 10 //设置超时时间,单位为秒
3.执行ssh命令
spawn ssh $user@$ip
4.终端输出包含字符串"password:",输入密码,记得加上\r
expect "password:"{send "$pwd\r"}
5.终端输出分支
expect{
“yes/no”{send "yes\r"; exp_continue}
"password:"{send "$pwd\r"}
}
6.设置终端输出终止符,并退出脚本
expect eof
exit
ฅ平平庸庸的普通人ฅ