Here is essentially what I am doing... I have been charged with the task of unifying all local login information for about 300 Unix machines. This means UID's, GID's, etc... What I have done, is created a perl script, that will harvest all the lines in /etc/passwd (this will be adapted for shadow and group as well - it's only a matter of changing the source to the file handle) - and then map them using a key=>value pair of the username=>line_in_passwd. I then use a simple while loop to parse each value, split it into the actual data (sans :), and use a DBI call to place it into a MySQL DB, along with the current working hostname. I have also populated an array with the usernames, the idea being that if a key matches an entry in the array, the DB already contains the info for that user/host pair, and it should branch to then check the values of that user, to ensure nothing has changed. As of now, it does not branch, I have been simply playing with the logic to ensure that if the statement is true, it will. Here is a snippet of that logic block. Please excuse the syntax...for I am nowhere near as effective yet as I would like to be :)
CHILD:while( (my $key, my $value) = each %passwd){ for(@existing_users){next CHILD if /$key/;} $value =~ /\w*:(.*):(\d*):(\d*):(.*):(.*):(.*)/; my $query = "INSERT INTO passwd (username, pwd_loc, uid, gid, +gecos, home_dir, shell, hostname) values('$key', '$1', '$2', '$3', '$ +4', '$5', '$6', '$hostname')"; my $sth = $dbh->prepare($query); $sth->execute() || die("Couldn't exec sth!"); }
The next CHILD if statement will be replaced with a subroutine to check for differences if I can get this right. My thought, regarding the hash order, was to see if there may be a better way to scan that hash for an existing user entry in the DB. And just by the way - I know that you Monks are huge advocates of using .pm's. There may indeed be one out there that I could adapt for this, however, being as new as I am to both Perl, and programming in general, it's in my best interest to reinvent the wheel :) Thanks again for the help Monks.

In reply to Re^2: Determining hash order for sorting array by PenguinPwrdBox
in thread Determining hash order for sorting array by PenguinPwrdBox

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.