Hi there,
The script is still not working it just execute and does nothing to /etc/passwd and it gives no errors this time. Please check below I have attached my /etc/passwd output before executing the script then the content of the script and output produced after execution check /etc/passwd work nothing has been updated. I actually tested it on two servers which are server1 and server2 same output nothing updated.
ntp:x:38:38::/etc/ntp:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
distcache:x:94:94
istcache:/:/sbin/nologin
postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
named:x:25:25:Named:/var/named:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
student2:x:500:500:student2:/home/student2:/bin/bash
web:x:100:48:Web File Owner:/home/web:/bin/bash
SINLO_R:x:501:501::/home/SINLO_R:/bin/bash
AVNLNX:x:502:502::/home/AVNLNX:/bin/bash
REGGIE_P:x:503:503::/home/REGGIE_P:/bin/bash
STONE_P:x:504:504::/home/STONE_P:/bin/bash
GCOGCO:x:505:505::/home/GCOGCO:/bin/bash
NDUMIE:x:506:506::/home/NDUMIE:/bin/bash
MANGI:x:507:507::/home/MANGI:/bin/bash
MZIZA_G:x:508:508::/home/MZIZA_G:/bin/bash
[root@server2 script]# date
Thu Jan 22 21:49:49 SAST 2009
#!/bin/bash
FILE1=/tmp/update.txt
FILE2=/etc/passwd
cp $FILE2 /etc/passwd.$$.orig
TEST=echo
for i in `awk -F: '$1 == "'"$HOSTNAME"'" { print $2 }' $FILE1`
do
if awk -F: '$1 == "'"${i}"'" { found=1; exit; } END { exit(!found);}' $FILE2
then
FIELD1=`awk -F: '$1 == "'"$HOSTNAME"'" && $2 == "'"${i}"'" { print $3;exit; }' $FILE1`
$TEST usermod -c "${FIELD1}" $i
fi
done
~
~
[root@server2 script]# ls
unixscript.txt
[root@server2 script]# ./unixscript.txt
[root@server2 script]#
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
pcap:x:77:77::/var/arpwatch:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
distcache:x:94:94
istcache:/:/sbin/nologin
postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
named:x:25:25:Named:/var/named:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
student2:x:500:500:student2:/home/student2:/bin/bash
web:x:100:48:Web File Owner:/home/web:/bin/bash
SINLO_R:x:501:501::/home/SINLO_R:/bin/bash
AVNLNX:x:502:502::/home/AVNLNX:/bin/bash
REGGIE_P:x:503:503::/home/REGGIE_P:/bin/bash
STONE_P:x:504:504::/home/STONE_P:/bin/bash
GCOGCO:x:505:505::/home/GCOGCO:/bin/bash
NDUMIE:x:506:506::/home/NDUMIE:/bin/bash
MANGI:x:507:507::/home/MANGI:/bin/bash
MZIZA_G:x:508:508::/home/MZIZA_G:/bin/bash
[root@server2 script]# date
Thu Jan 22 21:52:19 SAST 2009
[root@server2 script]#
Thanks