expect--自动批量分发公钥脚本
生活随笔
收集整理的這篇文章主要介紹了
expect--自动批量分发公钥脚本
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.在使用之前,先安裝epel源,yum install expect -y
2.寫分發腳本,后綴為exp
#!/usr/bin/expect
set host_ip [lindex $argv 0]
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $host_ip
expect {-timeout 60"(yes/no)?" { send "yes\n";exp_continue}"password:" { send "Ak46\n"}timeout {puts "Connect timeout!";return}
}
expect eof
exit -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
?
轉載于:https://www.cnblogs.com/Dev0ps/p/10124715.html
總結
以上是生活随笔為你收集整理的expect--自动批量分发公钥脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 冰雪女皇买吗
- 下一篇: 我想要清零 是什么歌啊?