I have updated the script but it's still not working please have a look below.
#!/bin/bash
FILE1=/tmp/update.txt
FILE2=/etc/passwd
cp $FILE2 /etc/passwd.$$.orig
TEST=echo
for i in `awk -F: '$1 == "'"$HOSTNAME"'" && $2 == '"${i}"' { print $2 }' $FILE1`
do
if awk -F: '$1 == "'"${i}"'" { exit(0); } END { exit(1);}' $FILE2
then
FIELD1=`awk -F: '$2 == "'"${i}"'" { print $3 }' $FILE1`
$TEST usermod -c "${FIELD1}" $i
fi
done
~
[root@server1 script]# ./scriptlinuxcom.txt
awk: $1 == "server1.localdomain" && $2 == { print $2 }
awk: ^ syntax error
[root@server1 script]#
I'm still getting syntax error's when executing the script.If you look below at the last six users
my /etc/password comment field has not been updated with the comments from the /tmp/update.txt.
/etc/passwd
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
student1:x:500:500:student1:/home/student1:/bin/bash
web:x:100:48:Web File Owner:/home/web:/bin/bash
SINLO_R:x:501:501:SINLO ROGGER :/home/SINLO_R:/bin/bash
AVNlnx:x:502:502:LINUX Admistrator/junior:/home/AVNlnx:/bin/bash
REGGIE_P:x:503:503:REGGIE PABLO:/home/REGGIE_P:/bin/bash
STONE_P:x:504:504:STONE PANE:/home/STONE_P:/bin/bash
SINLOR:x:505:505:SINLO ROGGER :/home/SINLOR:/bin/bash
GUGU_M:x:506:506::/home/GUGU_M:/bin/bash
SANDISA:x:507:507::/home/SANDISA:/bin/bash
GCOGCO:x:508:508::/home/GCOGCO:/bin/bash
NDUMIE:x:509:509::/home/NDUMIE:/bin/bash
MANGI:x:510:510::/home/MANGI:/bin/bash
MZIZA_G:x:511:511::/home/MZIZA_G:/bin/bash
/tmp/update.txt
[root@server1 etc]# cat /tmp/update.txt
SERVER1:SINLO_R:SINLO ROGGER
SERVER1:AVNlnx:LINUX Admistrator/junior
SERVER1:nfsnobody:LINUX Admistrator
SERVER1:REGGIE_P:REGGIE PABLO
SERVER1:STONE_P:STONE PANE
SERVER1:GUGU_M:LINUX ENGINEER
SERVER1:SANDISA:SYSTEM ADMIN
SERVER1:GCOGCO:MTN OPERATOR
SERVER1:NDUMIE:MTN OPERATOR
SERVER1:MANGI
BA ORACLE
SERVER1:MZIZA_G:SPECIALIST ORACLE
SERVER2:SINLO_R:SINLO ROGGER
SERVER2:AVNLNX:LINUX Admistrator/junior
SERVER2:nfsnobody:LINUX Admistrator
SERVER2:REGGIE_P:REGGIE PABLO
The is another script that was created for me this script worked fine but because it was not using usermod it
updated the /etc/shadow id and then this made users when loggining on appear with out user name's.
This is the script:
FILE1=/tmp/update.txt
FILE2=/etc/passwd
cp $FILE2 /etc/passwd.orig
awk 'BEGIN{FS=OFS=":"} NR==FNR{a[$2]=$3;next}
$1 in a && $5==""{$5=a[$1]} {print}' "$FILE1" "$FILE2" > passwd_new
mv passwd_new $FILE2
~
~
[root@server1 script]# ./scriptgugu.txt
[root@server1 script]#
If you now look at the /etc/passwd the comment field has been updated but now when I loggon to the system
with the users I have problems of them logging in but after that the command prompt appears with out a username.
e.g. ReGGIE_P will logon to the system but the prompt will have " I don't have a username linked to this id 435$ "
This created problems for me as some of the accounts a used to run applications.
This is the out put of /etc/passwd asfter executing the scrip:
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
student1:x:500:500:student1:/home/student1:/bin/bash
web:x:100:48:Web File Owner:/home/web:/bin/bash
SINLO_R:x:501:501:SINLO ROGGER :/home/SINLO_R:/bin/bash
AVNlnx:x:502:502:LINUX Admistrator/junior:/home/AVNlnx:/bin/bash
REGGIE_P:x:503:503:REGGIE PABLO:/home/REGGIE_P:/bin/bash
STONE_P:x:504:504:STONE PANE:/home/STONE_P:/bin/bash
SINLOR:x:505:505:SINLO ROGGER :/home/SINLOR:/bin/bash
GUGU_M:x:506:506:LINUX ENGINEER:/home/GUGU_M:/bin/bash
SANDISA:x:507:507:SYSTEM ADMIN:/home/SANDISA:/bin/bash
GCOGCO:x:508:508:MTN OPERATOR:/home/GCOGCO:/bin/bash
NDUMIE:x:509:509:MTN OPERATOR:/home/NDUMIE:/bin/bash
MANGI:x:510:510
BA ORACLE:/home/MANGI:/bin/bash
MZIZA_G:x:511:511:SPECIALIST ORACLE:/home/MZIZA_G:/bin/bash
look at the last six fields the comment field has been updated.
Please asssist I hope this can give u an idea of the problem.
Thanks for all the help.