- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell to perl script
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
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
тАО11-12-2010 04:40 AM
тАО11-12-2010 04:40 AM
i would like to convert a small shell script to perl.
-------
for NODE in `cat node-list.txt`
do
#run this commnad opcragt $NODE
#and check the output is like this
#Node specified with Primary Node Name is not managed by HPOM for Windows
#write that node name into a file
if [ opcragt $NODE | grep HPOM ]
echo $NODE >> node-not-available.txt
#if yes, mean, node is not managed
----------
thanks...
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2010 05:36 AM
тАО11-12-2010 05:36 AM
SolutionProvide a good/bad example for better help.
2) You may want to use the -all option and parse the output against a pre-read node list.
Check out: http://perlmeme.org/faqs/system/system.html
Anyway... 1) could be done using something like:
# perl x.pl < node-list.txt >> node-not-available.txt
where (untested) ...
-- x.pl --
use strict;
use warnings;
while (my $node = <>) {
chomp $node;
for (qx(opcragt $node)) {
if (/HPOM/) {
print qq($node\n);
last;
}
}
}
Hope this help some,
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2010 05:47 AM
тАО11-12-2010 05:47 AM
Re: shell to perl script
You haven't provided a shell script other than in pseudocode. Using 'echo' instead of 'opcragt' to demonstrate, if you had something like:
# cat ./mysh
#!/bin/sh
for NODE in $(< node-list.txt)
do
if [ $(echo $NODE | grep -s HPOM) ]; then
echo "${NODE} not managed"
else
echo "${NODE} managed"
fi
done
...in Perl, we could do:
# cat ./mypl
#!/usr/bin/perl
use strict;
use warnings;
my $result;
while (<>) {
chomp;
$result = `echo $_ | grep -s HPOM`;
if ( $result =~ /HPOM/ ) {
print "$_ not managed\n"
}
else {
print "$_ managed\n"
}
}
1;
...which given an input file named 'node-list.txt' would be run like:
# ./mysh
(or):
# ./mypl node-lst-txt
If the contents of the input looked like:
# cat node-list.txt
node_one
node_two
node_HPOM
node_three
...then the output of either the shell or the Perl script would be:
node_one managed
node_two managed
node_HPOM not managed
node_three managed
You can redirect the output when you run either variation. I prefer to do this rather than embed that logic.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2010 06:59 AM
тАО11-12-2010 06:59 AM
Re: shell to perl script
one more small grep help...i am having two list of nodes. i want to compare them and make the list of nodes present in fair and missing in app1
ie,
grep $NODE app1-node-list >>present
if $NODE not present in app1 node list, i want to write it in a new file...how to do that please....
root@fair> ll
total 224
-rw-r--r-- 1 root sys 85757 Nov 12 01:47 app1-node-list
-rw-r--r-- 1 root sys 19198 Nov 12 08:25 fair-node-list
root@fair>
root@fair> for NODE in `cat fair-node-list`
> do
> grep $NODE app1-node-list >>present
> done
root@fair> ll
total 256
-rw-r--r-- 1 root sys 85757 Nov 12 01:47 app1-node-list
-rw-r--r-- 1 root sys 19198 Nov 12 08:25 fair-node-list
-rw-r--r-- 1 root sys 14017 Nov 12 09:28 present
root@fair> wc *
7637 7660 85757 app1-node-list
1576 1570 19198 fair-node-list
1192 1192 14017 present
10405 10422 118972 total
root@fair>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2010 07:23 AM
тАО11-12-2010 07:23 AM
Re: shell to perl script
well, you could just use :
grep -f app1-node-list fair-node-list
Beware that the lines in the first file mentioned are treated as regular expression PATTERNs. Do depending on needs, feeds and platform you may want to add any or all of:
-i, ignore case distinctions
-w, force PATTERN to match only whole words
-x, force PATTERN to match only whole lines
If you need more work to be done, then the following working, rough, framework may help:
perl present.pl app1-node-list fair-node-list
where
----------------- present.pl -------
use strict;
use warnings;
my %first;
my $input_file = shift or die "Need a first file to work on";
open (FILE, "<$input_file") or die "Could not open first file $input_file\n$!";
$first{$_}=1 for (
print scalar keys %first, " lines in first $input_file\nPresent:\n";
$input_file = shift or die "Need a second file to work on";
open (FILE, "<$input_file") or die "Could not open second file $input_file\n$!";
for (
print if $first{$_};
}
Enjoy,
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2010 07:28 AM
тАО11-12-2010 07:28 AM
Re: shell to perl script
It reads a first file and for each line creates a hash array element with the whole line as key.
For some usages you may want to add a 'chomp' to this to remove the newline, and a uc or lc to force upper or lower case.
Then it reads the second file iterating over that and trying each line as key into the array. If found then print, else onto the next line.
The 'else' could do other stuff.
It could also play futher with the array to create a driver table for the 'opcrag' command.
Or when using opcarg -all, then you migh be able to use the arrays to do the right processing for the nodes reported on.
Cheers,
Hein