expect--自动批量分发公钥脚本
发布日期:2021-05-08 23:24:56 浏览次数:19 分类:博客文章

本文共 502 字,大约阅读时间需要 1 分钟。

1.在使用之前,先安装epel源,yum install expect -y

2.写分发脚本,后缀为exp

#!/usr/bin/expectset host_ip [lindex $argv 0]spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $host_ipexpect {        -timeout 60        "(yes/no)?" { send "yes\n";exp_continue}        "password:" { send "Ak46\n"}        timeout {puts "Connect timeout!";return}}expect eofexit -onexit {        send_user "Job has finished!"}

注:set的作用是设置变量,spawn设置执行命令时,可以引用变量;变量的第一个参数为0

3.执行以下命令开始分发

for ip in `cat /root/ip.txt`;do expect /root/fenfa_sshkey.exp $ip ;done

 

上一篇:java.net.SocketException: 权限不够
下一篇:oracle数据库默认是10次尝试失败后锁住用户

发表评论

最新留言

关注你微信了!
[***.104.42.241]2025年04月15日 03时36分10秒