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


In reply to Building data structure from several /etc/passwd files by tux242

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.