| Description When deleting a user account from a Linux/Unix system,
system administrators sometimes forget to
delete that user from /etc/group. This motivates the development of this
script.
This script requires two input files: the passwd and the group files. Since each line of the passwd file contains 7 colon-separated fields while each line of the group file contains only 4 ones. We can use this to figure out whether a line should be interpreted as a passwd record or a group one. The sample passwd file is: root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
solomon:x:500:500::/home/changyj:/bin/bash
qoo:x:501:100::/home/qoo:/bin/bash
joshua:x:503:100::/home/joshua:/bin/bash
abigail:x:504:100::/home/abigail:/bin/bash
eric:x:504:100::/home/eric:/bin/bash
jonathan:x:504:100::/home/jonathan:/bin/bash
johnson:x:505:100::/home/johnson:/bin/bash
tina:x:506:100::/home/tina:/bin/bash
tracy:x:507:100::/home/tracy:/bin/bash
and the sample group file is: root:x:0:root
sales:x:501:johnson,joshua,kelly
grp01:x:502:eric,johnson,kelly,ping,abigail,jonathan,tracy,qoo
grp02:x:503:john,qoo,ping,solomon
grp03:x:504:solomon,david,eric,qoo
adm:x:505:solomon,tina,ping,abigail,david
where the names of non-existent users are shown in red.
We want to remove these non-existent users from the group file. | |||||||||||||||||
Script and Comments
| |||||||||||||||||