- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help required Unix script to compare group file.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2008 03:04 PM
тАО02-28-2008 03:04 PM
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.
Sreeram
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2008 03:34 PM
тАО02-28-2008 03:34 PM
Re: Help required Unix script to compare group file.
Please send me money.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2008 03:51 PM
тАО02-28-2008 03:51 PM
Re: Help required Unix script to compare group file.
First I would generate 2 intermediate files
root 0 user1
root 0 user2
root 0 user3
adm 1 userx
adm 1 usery
then to compare:
diff gr.intermediate0 gr.intermediate1
to merge
sort -u gr.intermediate0 gr.intermediate1 >gr.intermediate.out
script to generate intermediate file
#!/usr/bin/ksh
while read in
do
n1="${in%%:*}"
n2="${in%:*}"
n2="${in#*:}"
users="${in##*:}"
while [ ! -z "$users" ]
do
echo "$n1" "$n2" "${users%%,*}"
newusers="${users#*,}"
if [ "$newusers" = "$users" ]
then
break
fi
done
done
.....
to use: generateintermediate/tmp/gr.intermediate1
now to regenerate the file after merge with sort or diff:
#!/usr/bin/ksh
N=""
while read a b c
do
if [ "$N" != "$a" ]
then
echo "\n$a:$b:$c\c"
$N="$a"
else
echo ",$c\c"
fi
done
echo "\n"
.....
to regenerate a group file:
regengrp /tmp/newgroup
I did not test it, but should work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-29-2008 07:22 AM
тАО02-29-2008 07:22 AM
Re: Help required Unix script to compare group file.
I have checked the below scripts and it is not giving any output. Could you please help me to resolve this. I am not scripting expert thats why I am troubling you.
Thanks
Sreeram
#!/usr/bin/ksh
while read in
do
n1="${in%%:*}"
n2="${in%:*}"
n2="${in#*:}"
users="${in##*:}"
while [ ! -z "$users" ]
do
echo "$n1" "$n2" "${users%%,*}"
newusers="${users#*,}"
if [ "$newusers" = "$users" ]
then
break
fi
done
done
.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-29-2008 07:47 AM
тАО02-29-2008 07:47 AM
Re: Help required Unix script to compare group file.
while [ ! -z "$users" ]
do
echo "$n1" "$n2" "${users%%,*}"
newusers="${users#*,}"
if [ "$newusers" = "$users" ]
then
break
fi
users="$newusers"
done
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-29-2008 07:58 AM
тАО02-29-2008 07:58 AM
Re: Help required Unix script to compare group file.
#!/usr/bin/ksh
while read in
do
n1="${in%%:*}"
n2="${in%:*}"
n2="${n2#*::}"
users="${in##*:}"
while [ ! -z "$users" ]
do
echo "$n1" "$n2" "${users%%,*}"
newusers="${users#*,}"
if [ "$newusers" = "$users" ]
then
break
fi
users="$newusers"
done
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-29-2008 08:02 AM
тАО02-29-2008 08:02 AM
Re: Help required Unix script to compare group file.
#!/usr/bin/ksh
N=""
while read a b c
do
if [ "$N" != "$a" ]
then
echo "\n$a::$b:$c\c"
$N="$a"
else
echo ",$c\c"
fi
done
echo "\n"
.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-29-2008 12:11 PM
тАО02-29-2008 12:11 PM
Re: Help required Unix script to compare group file.
Please send me money.
:-)
Sounds good to me.
If we do a persons work, we get the money!
So 'points' nor pride cut it for you Steven ?
:-)
I agree with that, but I do have a de-luxe version floating around. In perl...
$ cat merge_groups.pl
use strict;
use warnings;
my ($old, $line, %groups,%x);
$old='';
while (<>) {
my $flagged;
chomp;
while (/(.*):(\d+):(\w+)/) {
my $g = sprintf("%05d", $2); # help sort
if ($groups{$g} && $1 ne $groups{$g}) {
print STDERR "Groupname mismatch on line: $_\n" unless $flagged ++;
} else {
$groups{"$g"} = $1;
}
$x{"$g $3"}++;
s/:$3,?/:/
}
}
foreach (sort keys %x) {
my ($g,$u) = split;
if ($g eq $old) {
$line .= ",$u";
} else {
print $line."\n" if $line;
$line = sprintf("%s:%d:%s",$groups{"$g"},$g,$u);
$old = $g;
}
}
print $line."\n";
usage:
#perl merge_groups.pl group1 group2 groupn > new
- sorts groups by number
- sorts users in the groups
- the first 'name' wins
- drops duplicate user names silently
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2008 11:52 PM
тАО03-02-2008 11:52 PM
Re: Help required Unix script to compare group file.
Thank you very much. Its works without any problem. One small isuue what I am facing is it drop the groups without out any member in it. If you can help me to resolve this it will be highly appreciable. I am not that much femiliar with scripts.
Thanks for Laurent for his kindness for sparing time to help me.
Regards
Sreeram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2008 08:31 AM
тАО03-03-2008 08:31 AM
SolutionHere is is again, with support for empty lines like a default /etc/group file has.
Note... the sorting by username makes 'root' not (always) show up first.
Hein.
------------------------------
use strict;
use warnings;
my ($old, $key, %groups,%x);
$old='';
while (<>) {
my $flagged;
chomp;
if (/^(\w+:[^:]*):(\d+):/) { # Line starts with group name:x:number?
my $g = sprintf("%04d", $2);
if ($groups{$g} && $1 ne $groups{$g}) {
print STDERR "Groupname mismatch on line: $_\n" unless $flagged ++;
} else {
$groups{"$g"} = $1;
$x{$g}++ # Empty lines are ok
}
s/$`/:/; # Strip the name:group now that it is processed
while (/:(\w+)/) { # User on the line?
$x{"$g $1"}++; # Remember this user
s/:$1,?/:/ # Strip user once processed
} # users
} # group
} # line
foreach $key (sort keys %x) {
my ($g,$u) = split /\s+/,$key;
if ($g eq $old) {
$_ .= "$u,";
} else {
if ($_) {
s/,?$/\n/; # Terminate
print;
}
$u = "" unless $u; # empty is ok.
$_ = sprintf("%s:%d:%s",$groups{"$g"},$g,$u);
$old = $g;
}
}
s/,?$/\n/; # Terminate
print;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2008 02:48 PM
тАО03-06-2008 02:48 PM
Re: Help required Unix script to compare group file.
Thanks a lot man. This what I was looking.
It is really helping me to for user /group migration
Thanks again
Regards.
Sreeram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2008 02:49 PM
тАО03-06-2008 02:49 PM
Re: Help required Unix script to compare group file.
Thanks to all who helped me.