操作环境:CentOS 7
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@localhost ~]#
条件:
1、可以ssh免密登陆
2、把需要修改root密码的主机ip地址,写进当前目录下的ip.txt
#!/usr/bin/bash
#create by liujun at 2020-03-08
#enter the change password
while :
do
read -s -p "Enter a New Password:" pass1
echo ""
read -s -p "Enter Your Password Agine:" pass2
if [ ! $pass1 == $pass2 ];then
echo ""
echo "The New password do not match,please re-enter"
else
break
fi
done
echo ""
echo "Entered successfully!"
#make sure the host is powered on and change password
for ip in $(cat ip.txt)
do
{
ping -c1 -W1 $ip &> /dev/null
if [ $? -eq 0 ];then
ssh $ip "echo $pass1 | passwd --stdin root"
if [ $? -eq 0 ];then
echo "$ip" >> ok_`date +%F`.txt
else
echo "$ip" >> fail_`date +%F`.txt
fi
else
echo "$ip" >>unonline_`date +%F`.txt
fi
}&
done
wait
echo "finish......"
来源:CSDN
作者:Mask_o
链接:https://blog.csdn.net/tenderness_xh/article/details/104734813