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% 22
192.168.18.218 root c87; ZNNL 22
# Cat Change_pass.sh
#!/bin/bash
Old_info=~/old_info
New_info=~/new_info
For IP in ' awk '/^[^#]/{print $ ' $OLD _info '; Do
User= ' awk-v i= $IP ' {if (i==$1) print $ ' $OLD _info '
Pass= ' awk-v i= $IP ' {if (i==$1) print $} ' $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 _info
Expect-c "
Spawn Ssh-p$port [email protected] $IP
Set Timeout 2
Expect {
\ "(yes/no) \" {Send \ "yes\r\"; Exp_continue}
\ "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% 22
192.168.18.218 root c87; ZNNL 22
Free pick up brother even it education original Linux OPS engineer video/Detailed Linux tutorials, details Inquiry official website customer Service: http://www.itxdl.net/linux/
Learn PHP, Linux, HTML5, UI, Android and other video tutorials (Courseware + notes + video)! Contact Q2430675018
Linux system bulk Modify user Password