tux242 has asked for the wisdom of the Perl Monks concerning the following question:
I have several boxes I am trying to cleanup, do audits on via /etc/passwd which is a : delimited file so i use split and a hash to get only the unique ids back, so if they are on several severs at once it gets lost in the reiteration, what I am wondering is 2 things how do i make the hash multidimensional one by pulling out whatever i need off of the passwd files from 9 or so different servers and like uid and gcos info (actually I already wrote this code-seen below)and two being able to tell exactly what info came from what passwd files like from what different servers. I have the passwd files named like this passwd.server1, passwd.server2,etc... I also want to know how to make the passwd array wildcarded in the passing so as not to have to write out each passwd file in the array itself, since they all begin with passwd anyway. Below is a working copy, for me anyway, of my code so far:
#! /usr/bin/perl @files=('passwd.server1','passwd.server2','passwd.server3','pa +sswd.server4', 'passwd.server5','passwd.server6','passwd.server7','passwd.server8 +','passwd.server9'); foreach $file (@files){ open (PASSWD,"$file"); $nf="endo"; open (NEWFILE, ">$nf"); while (<PASSWD>) { ($login, $passwd, $uid, $gid, $gcos, $home, $shell) = split(/:/); $USERS{$login} = $gcos; } close (PASSWD); } + foreach $login (sort keys %USERS) { $gcos = $USERS{$login}; print NEWFILE "$login, $gcos\n"; }
Thanks for your help!!
Tux242
Edited 2003-10-30 by Ovid
Title edit by tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: /etc/passwd
by Limbic~Region (Chancellor) on Oct 30, 2003 at 22:09 UTC | |
|
Re: /etc/passwd
by jasonk (Parson) on Oct 30, 2003 at 22:20 UTC | |
|
Re: /etc/passwd
by Zaxo (Archbishop) on Oct 31, 2003 at 00:32 UTC | |
|
Re: /etc/passwd
by pzbagel (Chaplain) on Oct 30, 2003 at 22:16 UTC | |
|
Re: /etc/passwd
by sauoq (Abbot) on Oct 31, 2003 at 00:35 UTC | |
|
Re: /etc/passwd
by hardburn (Abbot) on Oct 30, 2003 at 21:46 UTC | |
by tux242 (Acolyte) on Oct 30, 2003 at 21:56 UTC | |
by arden (Curate) on Oct 30, 2003 at 22:17 UTC |