tux242,
You have been working on this problem at least since 30 October. A lot of monks have spent a great deal of time both in replying to your posts and in the CB. I am more than willing to help you and even avoid modules if you will take the time to explain in clear and concise requirements what your ultimate goal is.

Here is an example of what I mean, which may or may not be what you are after.

EXAMPLE
I have been given the daunting task of ensuring uniformity of the user accounts and passwords across multiple *nix systems. I have already extracted a copy of all the /etc/passwd files from each of the servers and have used the following syntax for identifying them - passwd.hostname

I am trying to avoid using modules due to a number of reasons. The two biggest reasons is that my employer has made it a requirement and I need to be able to explain the code line by line. I do not mind "borrowing" ideas from modules, but ultimately the code needs to be my own.

So the type information I need to get out of my program is as follows:

  • Account x does not exist on hostname1 or hostname2
  • Account y's UID on hostname1 is #, but is # on hostname2
  • Account j's password on hostname1 is not the same as all the other machines.

    So basically, I need to compare every field against every other field as well as make provisions for the possibility the field won't exist at all on certain servers. My first hurdle is that the encrypted password is not stored in /etc/passwd but in /etc/shadow. I am using shadow.hostname syntax for that.

    Here is what I have come up with so far:

    #!/usr/bin/perl -w use strict; my @hosts = qw(zeus mercury athena); my (@p_files, @s_files); my %data; for my $host ( @hosts ) { push @p_files , 'passwd.' . $host; push @s_files , 'shadow.' . $host; } # Process /etc/passwd files FILE: for my $file ( @p_files ) { if ( ! open (PASSWD, $file) ) { warn "Unable to open $file : $!"; next FILE; } LINE: while ( <PASSWD> ) { my @fields = split /:/; if ( @fields != 7 ) { warn "$_ in file $file is corrupt"; next LINE; } $data{$fields[0]}->{$file} = \@fields; } } # Process /etc/shadow files FILE: for my $file ( @s_files ) { if ( ! open (SHADOW, $file) ) { warn "Unable to open $file : $!"; next FILE; } LINE: while ( <SHADOW> ) { # Not sure what to do here # but I know I need to modify # $data{account}->{$file}[1] } } # Need code help here to do all the comparisons I need
    Additionally, any help or insight would be appreciated. I am rather new to Perl so I understand this might not be the best approach. If you do choose to suggest an alternative approach, keep in mind my requirements I stated above
    END EXAMPLE

    I can guarantee tux242 that if you word take the time to pose a question like this you will be much more likely to get answers that you are seeking.

    Cheers - L~R


    In reply to How to ask for help by Limbic~Region
    in thread Standardized Template 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.