Pages

Thursday, April 24, 2014

Expect Bash script to change all username's password at a time in redhat/centos

Hi,

          If you want to change the password of all users in redhat,centos server at a time.I have developed one good expect script that will change all users password within few seconds in whole server.Below is the script to change password of all users in redhat/centos machine to same password.

        It will check for list of all users in the userlist.txt file which exists in the server.then with bash script automatically update all users password with the uniq password that you want to change.Don't forget to create userlist.txt file in the same folder where your script resides.




#Expect Script Developed By Krunal Patel
#!/usr/bin/expect -f 
read -p "Enter password that you want to set for all users: " pas 
for i in `cat userlist.txt `
do echo "$pas" | /usr/bin/passwd "$i" --stdin
echo "User $i password changed to $pas!" 
done 


        To download script click here

You will require to install expect package before using this script.

No comments:

Post a Comment

Please give us suggestions.

Shell Script Code