shell脚本使用expect交互

linux安装expect

yum install tcl-devel
yum install expect

#!/bin/bash
/usr/bin/expect <<EOF
set timeout 30
spawn ssh root@baba.fc417.top
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 root@baba.fc417.top:/root/lx
expect {
"*yes/no*" {send "yes\r"}
"*password*" {send "密码\r"}
}
expect eof
EOF

http://www.fc417.top

posted @ 2019-08-07 13:19  偷懒的fc  阅读(3390)  评论(0编辑  收藏  举报