两个用expect实现自动交互实例
1.
#!/bin/bash
password="iiecas123"
dest_dir="/vds/conf"
for i in `cat $1`
do
/usr/bin/expect << EOF
spawn scp ubase.dat $i:/vds/conf/ubase.dat
set timeout 60
expect {
expect "(yes/no)?" { send "yes\r\n" }
expect "password:" { send "$password\r\n" }
expect eof
}
EOF
done
2.
#!/bin/bash
echo OK
/usr/bin/expect << EOF
spawn ssh root@192.168.0.105
expect "password:"
set timeout 300
send "123456\r"
expect "]#"
send "exit\r"
expect eof
EOF