Question : Updating the gecos field on /etc/passwd file on different servers from a text file with the users an field information.

Hi there,

I need to updated the comments field on /etc/passwd on different servers from a list on a text file called update.txt for users that have a blank comments fields in their /etc/passwd file. The users have accounts on different servers. I have created a list of these users on a text file called update.txt. I need a script that will compare this file with /etc/passwd first backup the passwd database and update the comment/gecos field on /etc/passwd with the details on the text file if it's blank and if already updated leave it.
I have a script that I have created and it's not doing the job as I have not worked a lot with scripts.

Please assist
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
#!/usr/bin/bash
FILE1=/tmp/update.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
Open in New Window Select All

Answer : Updating the gecos field on /etc/passwd file on different servers from a text file with the users an field information.

Well, I see also that every single user is multiplied in your Linux2.txt file.

I think this is useless if the 3rd column is the same for all of them.
Random Solutions  
 
programming4us programming4us