- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script help
Operating System - HP-UX
1753774
Members
6951
Online
108799
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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-03-2006 05:10 PM
тАО02-03-2006 05:10 PM
script help
I have a flat file called input:
user|groupm groupb groupc goupa
userb|groupz group1d groupk
And I have a command string:
command user # command with ran against user
groupc groupa groupq groupb # output of command
what I need to do is
1. compare the input file with the output of the command and check to see if the groups are different and echo out OK if they are all the same or in sync or NOT OK if they are not in sync. And of course give me the results.
the input file can have 10 to 1000 lines. And the groups are not in any order from the command or in the input file.
Thanks
Jim
user|groupm groupb groupc goupa
userb|groupz group1d groupk
And I have a command string:
command user # command with ran against user
groupc groupa groupq groupb # output of command
what I need to do is
1. compare the input file with the output of the command and check to see if the groups are different and echo out OK if they are all the same or in sync or NOT OK if they are not in sync. And of course give me the results.
the input file can have 10 to 1000 lines. And the groups are not in any order from the command or in the input file.
Thanks
Jim
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2006 03:07 AM
тАО02-04-2006 03:07 AM
Re: script help
If I had to do this through shell stuff only, then I'd take both target line and convert each to a file with a line per group.
Sort those, and diff.
But of course I would not solve it with a shell script but with perl. I've done something similar to your question before, and adapted it to do just what you want and then some.
Of course you may want to change the final return handling, and remove debug & detail printing.
---- input ----
user|group groupb groupc groupa
userb|groupk group1d groupz
---- tmp.txt ----
usera|groupm groupb groupc goupa
userb|groupz group1d groupk
user|groupa group groupX goupa
userc|groupz group1d groupkuser
---- command -----
#perl -ne "print if /user\|/" tmp.txt
user|groupa group groupX goupa
---- tmp.pl with perl solution (also attached) ---
$user = shift @ARGV or die "Must provide username";
$input = shift @ARGV or die "Must provide input file name";
open INPUT, "<$input" or die "Could not read file $input";
while () {
chomp;
$input_groups = $' if /^$user\|\s*/;
}
if ($_ = $input_groups) {
foreach $group (split) {
$input{$group}++;
}
$_ = `perl -ne "print \$' if /^$user\\|\s*/" tmp.txt`;
chomp;
print "-- $input_groups -- $_ --\n";
foreach $group (split) {
if ($input{$group}) {
delete $input{$group};
} else {
print "group $group for $user not found in $input\n";
$not = "NOT";
}
}
foreach $group (keys %input) {
print "group $group for $user not found in through command\n";
$not = "NOT";
}
print "${not}OK\n";
} else {
die "user $user not found"
}
----- usage samples -----
#perl tmp.pl userb input.txt
-- groupk group1d groupz -- groupz group1d groupk --
OK
#perl tmp.pl user input.txt
-- group groupb groupc groupa -- groupa group groupX goupa --
group groupX for user not found in input.txt
group goupa for user not found in input.txt
group groupb for user not found in through command
group groupc for user not found in through command
NOTOK
---------------
Enjoy,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-08-2006 01:57 PM
тАО02-08-2006 01:57 PM
Re: script help
So Jim... did that work for you? Hein.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP