Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking unix password file against the groupfile

Status
Not open for further replies.

ironpawz

IS-IT--Management
Oct 8, 2002
44
0
0
NZ

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(&quot; &quot;, $user[$i]);
$info[$i] = &quot;$logon[$i] $xfield[$i] $userid[$i] $group[$i]&quot;;
}

@sortline = sort {$a cmp $b} @info;

open(CYFUSERS, &quot;>> c:/temp/cyfusers.txt&quot;);

for ($i = 0; $i < scalar(@sortline); $i++)

{
next if $sortline[$i] eq &quot;&quot;;
print CYFUSERS &quot;$sortline[$i]\n&quot;;
}

close CYFUSERS;

# File created lets try matching it against our group file


open(CYFUSR, &quot;c:/temp/cyfusers.txt&quot;);
@cyfusr = <CYFUSR>;

for ($i = 0; $i < scalar(@cyfusr); $i++)
{
($login[$i], $first[$i], $lastn[$i], $grp[$i]) = split(&quot; &quot;, $cyfusr[$i]);
}

open(CYFGRP, &quot;c:/temp/usrgrp.txt&quot;); #this is a copy of the normal group file
@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 &quot;$cyfgrp[$i]&quot;;
}



 
Hi Bruce,

Turn your script into a FAQ, will fit right into the Tips and Tricks section. Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 

OK thanks for pointing my in the correct direction
 
Oops...

That was a bit terse from me. Nice script Bruce, sorry for seeming short with you, one of those days yesterday. Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Actually I thought you where nice and too the point in a friendly manner. No offence taken.

I have a question for you though. This site is called tek-tips and after 10 minutes of looking I could not figure out how to add one? I keep thinking I must be missing some huge buttone called &quot;Enter your tips for consideration here&quot; or something (which I probably still am). Where do I add a tip? I have a few probably helpfull tips (supprising for my poor perl skills) to contribute.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top