本文中涉及到主机口令加解密处理,相关脚本参考我的另外一篇文章:https://blog.csdn.net/qq_40809549/article/details/85095691
主机列表文件hosts.txt格式:ip;username;root's password,此处的root口令为加密处理后的密文,运行脚本时需要输入加密处理时所用的密钥。示例:
192.168.2.41;userA;U2FsdGVkX18AADWixNvl2jk3Gw6cF4z9naOfDzKms2o=
192.168.2.42;userA;U2FsdGVkX19Vr2LV8xnA/HKrK8RWqBw6ySdy2woijyY=
192.168.2.43;userA;U2FsdGVkX18HXor4q3klKwvueUDW/bAVxgmLhm21FVU=
192.168.2.43;userB;U2FsdGVkX18HXor4q3klKwvueUDW/bAVxgmLhm21FVU=
#!/bin/bash
remote_dir="/tmp"
remote_cmd="/usr/sbin/chpasswd -e < ${remote_dir}/chpass.txt;rm -f ${remote_dir}/chpass.txt"
>newpwd.txt
read -p "Please Input the encrypt key:" enc_key
#读取文件中的行
#cat hosts.txt|while read LINE 此处如果用这种写法在ssh时会报错,引起循环中断
for LINE in `cat hosts.txt&#