标签:color done 交互 ras 保存 code name end pre
#!/binbash rpm -qa |grep expect > /dev/null #判断是否已下载expect 若没有则下载该服务 a=`echo $?` [ ! $a -eq 0 ] && yum -y install expectif [ ! -e /root/.ssh/id_rsa.pub ];then #判断公钥是否已存在 没有则生成 /usr/bin/expect <<EOF set timeout 10 spawn ssh-keygen expect "id_rsa" send "\n" expect "passphrase" send "\n" expect "agian" send "\n" expect eof EOF fi while read file;do #遍历文件(ip 密码) ip=`echo "$file" |awk ‘{print $1}‘` #截取出ip passwd=`echo "$file" | awk ‘{print $2}‘` #截取出密码 /usr/bin/expect <<EOF set timeout 5 spawn ssh-copy-id -i $ip expect { "yes" { send "yes\n"; exp_continue } "$ip" { send "$passwd\n" } } expect eof EOF done < /root/host_name #保存ip 密码的文件路径 可自定义
cat /root/host_name
192.168.198.150 xxxxxxx 192.168.198.151 xxxxxxx 192.168.198.152 xxxxxxx 192.168.198.153 xxxxxxx ......
标签:color done 交互 ras 保存 code name end pre
原文地址:https://www.cnblogs.com/Xinenhui/p/13916228.html