I wrote this script to check our group file to see if there was any user in there that are not in the password file. It also puts the full username in the password file which is real handy. I know the perl is poor (It was also a learning exercise) but it works really well. Best I share something usefull if I'm going to ask questions as I can't answer many!
It creates a file from the password file that has just login names and proper user names. It then goes through the group file and replaces all login names with full names. Any name that does not get changed is not in the password file (and can after a check -trust nothing- be removed from the group file).
So you have a human readable list of users for each group and a list of users who need to be removed (no account no point in being in the group file).
I'm sure ppl here can improve it if you find the concept useful.
# Bruce Taylor get users for groups and "dead" users from groups
# Take all users from the password file and make a clean c:\temp\cyfusers.txt loginname user name
open(PASSWD, "c:/temp/passwd1);
@user = <PASSWD>;
for ($i = 0; $i < scalar(@user); $i++)
{
($logon[$i], $xfield[$i], $userid[$i], $group[$i]) = split(" ", $user[$i]);
$info[$i] = "$logon[$i] $xfield[$i] $userid[$i] $group[$i]";
}
@sortline = sort {$a cmp $b} @info;
open(CYFUSERS, ">> c:/temp/cyfusers.txt"
for ($i = 0; $i < scalar(@sortline); $i++)
{
next if $sortline[$i] eq "";
print CYFUSERS "$sortline[$i]\n";
}
close CYFUSERS;
# File created lets try matching it against our group file
open(CYFUSR, "c:/temp/cyfusers.txt"
@cyfusr = <CYFUSR>;
for ($i = 0; $i < scalar(@cyfusr); $i++)
{
($login[$i], $first[$i], $lastn[$i], $grp[$i]) = split(" ", $cyfusr[$i]);
}
open(CYFGRP, "c:/temp/usrgrp.txt"
@cyfgrp = <CYFGRP>;
for ($i = 0; $i < scalar(@cyfgrp); $i++)
{
for ($a = 0; $a < scalar(@login); $a++)
{
$cyfgrp[$i] =~ s/$login[$a]/$lastn[$a] $first[$a] $grp[$a]/;
}
print "$cyfgrp[$i]";
}