Hi there,
I have more that 300 servers that I need to updated the comments field on /etc/passwd for users that have a blank comments fields. The users have accounts on different servers. I have created a list of these users on a text file called update_passwd.txt.
I need a script that will compare this file with /etc/passwd first backup the passwd database and update the comment field on /etc/passwd with the details on the text file if it's blank.
I have a script that I have created not sure if it will do the job as I have not worked a lot with scripts.
Below is my script and attached is my text file:
#!/usr/bin/bash
FILE1=/tmp/update_passwd.txt
FILE2=/etc/passwd
cp $FILE2 /etc/passwd.orig
for i in `cat $FILE1 | awk -F":" '{ print $2 }'`
do
FIELD1=`cat $FILE1 | grep ${i} |awk -F":" '{ print $3 }'`
grep $i ${FILE2}
if [ $? -eq 0 ]
then
usermod -c "${FIELD1}" $i
fi
done
I will highly appreciate your assistance.