Hi Gurus,
Could you please help me to compare groups files of two diffrent servers in hp-ux as we sre doing server migration
group file 1
root:0:user1,user2,user3
adm:1:userx,usery
group file 2
root:0:user1,user3,user4,user5,user6,user7
adm:1:userx,usery,userz
final group
root:0:user1,user2,user3,user4,user5,user6,user7
adm:1:userx,usery,userz
my requirement is to generate the group file something similar to the file "final group"
please send me a script that can do this job
Thanks in Advance
Johnson
#!/usr/bin/perl -w
foreach $file (@ARGV) {
open(GROUPFILE, "<$file") || die "Could not open $file for reading $!";
while (<GROUPFILE>) {
($group,$gid,$users)=split(/:/);
if (defined($groups{"${group}:${gid}"}) {
$groups{"${gid}:${group}"}.=",$users";
} else {
$groups{"${gid}:${group}"}=$users;
}
}
close(GROUPFILE);
}
foreach $grouppair (sort keys(%groups)) {
($gid,$group)=split(/:/,$grouppair);
print "${group}:${gid}:$groups{$grouppair}\n";
}
Untested and it doesn't deal with a user appearing in the same group on two different group files (it will appear twice int eh resulting group file at the moment).
usage:
scriptname.pl groupfile1 groupfile2 groupfile3 ... > finalgroupfile
Hi Thanks for helping me
could you please look into the error
syntax error at ./compare.pl line 6, near ") {"
syntax error at ./compare.pl line 8, near "} else"
Execution of ./compare.pl aborted due to compilation errors.
[root@john]#
Thanks!!
John
I have edited the script but not giving the result
its giving o/p like
root::0
sys::3
tty::10
unix::208
users::20
#!/usr/bin/perl -w
foreach $file (@ARGV) {
open(GROUPFILE, "<$file") || die "Could not open $file for reading $!";
while (<GROUPFILE>) {
($group,$gid,$users)=split(/:/);
if (defined($groups{"${group}:${gid}"})) {
$groups{"${gid}:${group}"}.=",$users";
} else {
$groups{"${gid}:${group}"}=$users;
}
}
close(GROUPFILE);
}
foreach $grouppair (sort keys(%groups)) {
($gid,$group)=split(/:/,$grouppair);
print "${group}:${gid}:$groups{$grouppair}\n";
}
Please help