expect--自动批量分发公钥脚本

it2022-05-05  133

1.在使用之前,先安装epel源,yum install expect -y2.写分发脚本,后缀为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设置执行命令时,可以引用变量;变量的第一个参数为03.执行以下命令开始分发

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

 

转载于:https://www.cnblogs.com/Dev0ps/p/10124715.html

相关资源:各显卡算力对照表!

最新回复(0)