Compare lines from /etc/group on different servers

Discussion in 'Perl Misc' started by mac8500, Apr 24, 2006.

  1. mac8500

    mac8500 Guest

    Simple script:

    I run it .... server$ ./group.pl ./tmp/test.group.* > group.csv (where
    * is servernames).

    more ./tmp/test.group.server1

    This is to output the group id's in a file readable by excel BUT i need
    to find the differences between the servers.

    I tought i could put my first pass threw the file and put the entire
    line in a $ so i could compare the lines between them and if they don't
    match just print it ... but i couldn't get that to work ... i'm sure it
    easy i just can't get a grasp on a simple solution.

    Thanks.

    ***!!!***!!!*** server1
    system:0
    staff:1
    bin:2
    sys:3
    adm:4
    uucp:5
    mail:6
    security:7
    cron:8
    printq:9
    audit:10
    nobody:4294
    usr:100


    #!/usr/bin/perl

    my @servers;

    while(<>) {
    my($line) = $_;
    chomp($line);
    if ($line =~ /\*\*\*/) {
    $currentserver = substr $line, 16;
    push (@servers,$currentserver);
    } else {
    ( $login, $userid, $gid, ) = split( ':' );
    chomp($gid);
    $users{ $login }{ $currentserver } = $gid;
    }
    }

    #
    # Main program.
    #

    print "USERNAMES";

    foreach $servername (sort @servers) {
    print ",".$servername
    }

    print "\n";

    foreach $login (sort keys %users) {
    print $login;
    foreach $servername (sort @servers) {
    if ($users{$login}{$servername} >= 0) {
    print ",".$users{$login}{$servername};
    } else {
    print ", ";
    }
    }
    print "\n";
    }
    close FILES;
     
    mac8500, Apr 24, 2006
    #1
    1. Advertising

  2. mac8500 <> wrote:


    > print "USERNAMES";
    >
    > foreach $servername (sort @servers) {
    > print ",".$servername
    > }
    >
    > print "\n";



    You could replace all of that with:

    print join(",", "USERNAMES", sort @servers), "\n"; # untested


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Apr 24, 2006
    #2
    1. Advertising

  3. mac8500

    Guest

    #==================================================
    # this will match all or none
    #==================================================
    open(S1,"s1.txt") or die "Couldn't open s1.txt";
    my @s1 = <S1>;
    close(S1);

    open(S2,"s2.txt") or die "Couldn't open s2.txt";
    my @s2 = <S2>;
    close(S2);

    chomp(@s1); # remove newlines
    chomp(@s2); # remove newlines


    my $s1Str = join( ",", sort @s1 );
    my $s2Str = join( ",", sort @s2 );

    print $s1Str . "\n";
    print $s2Str . "\n";

    if ( $s1Str eq $s2Str ) {
    print "We have a match\n";
    }else{
    print "Servers have distint listings \n";
    }


    #==================================================
    # might want to match on an entry by entry basis
    #==================================================
    #
    # To compare two arrays I would advise using a module
    #
    http://www.annocpan.org/~DAVECROSS/Array-Compare-1.13/lib/Array/Compare.pm
    #
    # or you can use the simple N^2 method below
    #

    foreach $s1val ( sort @s1 ){

    foreach $s2val ( sort @s2 ){

    if ( $s1val eq $s2val ){
    print "We have a match: $s1val == $s2val\n";
    }

    }
    }

    -Steven
    The World's Tastiest Database
    http://www.iamfood.com
     
    , Apr 25, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robin Cull
    Replies:
    5
    Views:
    442
    Andrew Dalke
    Jul 31, 2003
  2. =?Utf-8?B?UGF0Qg==?=

    Different connection strings for different web servers

    =?Utf-8?B?UGF0Qg==?=, Jul 5, 2007, in forum: ASP .Net
    Replies:
    11
    Views:
    662
    Steven Cheng[MSFT]
    Jul 11, 2007
  3. Kevin Walzer

    Re: PIL (etc etc etc) on OS X

    Kevin Walzer, Aug 1, 2008, in forum: Python
    Replies:
    4
    Views:
    456
    Fredrik Lundh
    Aug 13, 2008
  4. bluebaron
    Replies:
    3
    Views:
    787
    Jonathan N. Little
    Nov 4, 2009
  5. PerlFAQ Server
    Replies:
    0
    Views:
    180
    PerlFAQ Server
    Jan 14, 2011
Loading...

Share This Page