Scripting Purpose: bulk modification of Linux system user passwords
Condition: The user who must be modified is root because only root has permission to use the passwd command
Description: the IP, user, password, port information is written to the Old_info file, the script reads the corresponding information from this file, using the expect-free interactive landing system. Modify the randomly generated 8-bit password to the root user's new password. Then save the new password to the Net_info file.
# cat old_info # ip user passwd port#----------------------- -------------------------192.168.18.217 root n8wx3mu% 22192.168.18.218 root c87; Znnl 22
# cat change_pass.sh#!/bin/bashold_info=~/old_infonew_info=~/new_infofor ip in ' awk '/^[^#]/{print $1} ' $OLD _info '; do user= ' awk -v i= $IP ' {if (i==$1) print $2} ' $OLD _info ' pass= ' awk -v i= $IP ' {if (i==$1) print $3} ' $OLD _info ' port= ' awk -v i= $IP ' {if (i==$1) print $4} ' $OLD _info ' new_pass= ' mkpasswd -l 8 ' echo "$IP $USER $NEW _pass $PORT " >> $NEW _infoexpect -c " spawn ssh -p$ Port [email protected] $IP set timeout 2 Expect { \ "(yes/no) \" {send \ "yes\r\"; exp_ Continue} &nbSp; \ "Password:\" {send \ "$PASS \r\";exp_continue} \ "[email protected]*\" {send \ "echo \ ' $NEW _pass\ ' |passwd -- stdin $USER \r exit\r\ "; exp_continue} #\" [email Protected]*\ " {send \" df -h\r exit\r\ "; exp_continue} }" done
# cat New_info 192.168.18.217 root n8wx3mu% 22192.168.18.218 root c87; ZNNL 22
This article is from the "Li Zhenliang Technology Blog" blog, make sure to keep this source http://lizhenliang.blog.51cto.com/7876557/1674791
Linux system bulk Modify user Password