您的位置:首页 > 其它

expect 自动输入密码

2017-11-14 11:43 113 查看
测试环境centos 6.5 7.4

1、远程登陆执行命令 scp

#!/bin/bash

expect -c '
set timeout 10000
spawn ssh root@192.168.67.22

#spawn scp ./3.sh 192.168.67.133:/root/zzx/

expect {
"yes/no" {send "yes\r"; exp_continue}
"*assword" {send "1\r"}
}
expect "#"
#send "ip a\r" #send "sleep 1\r"
send "hostname\r"
expect "#"
send "echo 123\r"
expect "#"
send "exit\r"
#interact #注释上面两行(exit去掉) 这一行注释去掉可以停在远程机器 interact
'
#以下和expect无关
#hostname
echo "end expect"

2、scp

#!/bin/bash
src=/root/zzx
dsc=/root/zzx
expect -c "
spawn scp -r $src/scp.sh root@192.168.67.133:$dsc
expect {
\"*assword\" {set timeout 300; send \"1\r\";}
\"yes/no\" {send \"yes\r\"; exp_continue;}
}
expect eof"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: