Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Compare lines from /etc/group on different servers

Reply
Thread Tools

Compare lines from /etc/group on different servers

 
 
mac8500
Guest
Posts: n/a
 
      04-24-2006
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;

 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      04-24-2006
mac8500 <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
 
sbusiello@gmail.com
Guest
Posts: n/a
 
      04-25-2006
#================================================= =
# 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/A...ray/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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 6.3 How can I pull out lines between two patterns that are themselves on different lines? PerlFAQ Server Perl Misc 0 04-19-2011 10:00 AM
FAQ 6.3 How can I pull out lines between two patterns that are themselves on different lines? PerlFAQ Server Perl Misc 0 01-14-2011 05:00 AM
Weird issue, same code, same browser, two different apache servers,very different css bluebaron HTML 3 11-04-2009 07:13 PM
Re: Vastly different ping times to two different servers in the sameroom...what can I do? Tony NZ Computing 0 06-10-2008 08:11 PM
Different connection strings for different web servers =?Utf-8?B?UGF0Qg==?= ASP .Net 11 07-11-2007 09:59 AM



Advertisments