记一次Shell脚本练习_批量主机root密码修改
操作环境: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 &>