#!/bin/bash
ip_array="192.168.2.41
192.168.2.42
192.168.2.43"
remote_dir="/tmp"
remote_cmd="/usr/sbin/chpasswd -e < ${remote_dir}/chpass.txt;rm -f ${remote_dir}/chpass.txt"
usernm="testuser"
echo "=======Please input the passwd for user:${usernm}======"
secpw=`openssl passwd -1`
echo $usernm":"$secpw >chpass.txt
echo "=======Get the passwd file:chpass.sh;start to batch update the password for ${usernm}"
for ip in ${ip_array}
do
cd /root
sshpass -p abcd1234 scp -o StrictHostKeyChecking=no chpass.txt root@$ip:${remote_dir}
sshpass -p abcd1234 ssh -o StrictHostKeyChecking=no -t root@$ip "${remote_cmd}"
echo "..........${usernm}@${ip} password updated!"
done
rm -f chpass.txt
echo "======done!!"