shell script using expect interaction

linux install expect

yum install tcl-devel
yum install expect

#!/bin/bash
/usr/bin/expect <<EOF
set timeout 30
spawn ssh [email protected]
expect {
"*yes/no*" {send "yes\r"}
"*password*" {send "密码\r"}
}
expect "root@*"
send "mkdir /root/fc/1231\r"
expect "root@*"
send "exit\r"
expect eof
spawn scp -r /root/fc/1231 [email protected]:/root/lx
expect {
"*yes/no*" {send "yes\r"}
"*password*" {send "密码\r"}
}
expect eof
EOF

Guess you like

Origin www.cnblogs.com/lazy-fc/p/11314708.html