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
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"
相关文章推荐
- 在 Linux 命令行脚本中执行 sudo 等命令时自动输入密码(使用expect)
- expect实现自动输入密码
- Linux下Expect 完成自动输入密码
- 用expect 实现切换用户时自动输入密码
- ssh非交互式密码授权(一):expect自动输入密码、命令
- shell脚本通过expect脚本实现自动输入密码
- Shell结合Expect实现自动输入密码
- 利用extect自动输入密码及expect的交叉编译
- 用expect 实现切换用户时自动输入密码
- sch远程拷贝自动输入密码expect小脚本
- linux-expect之无需输入密码自动登录
- 用expect 实现切换用户时自动输入密码 (转载)
- linux shell(/usr/bin/expect)实现自动输入密码登录,并执行命令
- linux、mac上用expect脚本实现脚本自动输入密码
- 用expect实现SCP/SSH自动输入密码登录
- 通过shell配合expect自动输入账号密码登陆ssh或ftp
- linux、mac上用expect脚本实现脚本自动输入密码
- python, linux shell 使用expect模块自动输入密码
- 使用expect自动输入ssh密码
- 使用expect脚本实现Linux中自动输入密码