Script objective: to modify linux user passwords in batches Condition: The modified user must be root, because only root has the permission to use the passwd command. Note: First, write the IP address, user, password, and port information to the old_info file. the script reads the corresponding information from this file and uses the login CT to log on to the system without interaction. Change the randomly generated 8-bit password to the new password of the root user. 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 $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_INFO CT-c" Spawn ssh-p $ PORT $ USER @ $ IP Set timeout 2 CT { \ "(Yes/no) \" {send \ "yes \ r \"; exp_continue} \ "Password: \" {send \ "$ PASS \ r \"; exp_continue} \ "$ USER @ * \" {send \ "echo \ '$ NEW_PASS \' | passwd -- stdin $ USER \ rexit \ r \"; exp_continue} # \ "$ USER @ * \" {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 Receive free Brothers IT education original linux O & M engineers video/detailed linux tutorial, details consulting official website Customer Service: http://www.lampbrother.net/linux/ Learn PHP, Linux, HTML5, UI, Android and other video tutorials (courseware + Notes + video )! Contact Q2430675018
|