in reply to 3par data acquistion
Why not use something like IO::Pipe and get rid of awk completely. I suspect that the code below is 'not ideal' for example you very likely don't want/need a sub call to run_command I pass in system, protocol (rsh|ssh) and command in my case so it ate the sub call for some flexibility
#!/usr/bin/perl use strict; use warnings; use IO::Pipe; my @systems = ('3par-S400','3par-E200'); my $system = undef; my $output = undef; my $command = undef; foreach $system (@systems) { $output = run_command($system); while (<$output>) { next if (m/^$/); last if (m/^Press.*/) #grab bits here instead of using awk } close($output); } sub run_command { my $system = shift; my $protocol = 'ssh'; my $command = "statvv -ni"; my $space = " "; #The following is bad but it works for now.. my $do_command = $protocol . $space . $system . $space . $command; my $cmd = new IO::Pipe; $cmd->reader($do_command); return $cmd; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: 3par data acquistion
by bluethundr (Pilgrim) on Aug 17, 2010 at 16:03 UTC | |
Just to give you a more complete idea of what I'm dealing with, here is a sample of the output of the statvv -ni commamd : Ideally what I would like to do is grab each discrete piece of info and stock that in it's own variable so that I can graph trends in each one. As much as I love perl, I'm a little too novice to do this just yet, tho I strive to be able to do things like this! As it stands now there is no output from the script. If I take the $output variable and print it, this is what I see: So I'm really unsure at this point how I can get at the data that I want. But it looks like you've dealt well with the end of the output with this chunk of code! Without access to awk, however, I am really unsure as to how I can grab the data I want and throw that into some variables I can use. Thanks | [reply] [d/l] [select] |
by callmeavis (Novice) on Aug 17, 2010 at 16:39 UTC | |
Use the "$_" scalar to work with individual lines inside the while loop. You can do something like this until you get comfortable with "$_" I'd also suggest looking at split to put the data into variables:
The last bit is the first 3 lines in this output; unless you need them for something I'd use the "last if" in the first code block above as a starting point; change last to next and modify the match m// | [reply] [d/l] [select] |
by bluethundr (Pilgrim) on Aug 23, 2010 at 17:18 UTC | |
Could someone please explain why these "my" variable are not correctly declared?
thank you monks for all your help so far! | [reply] [d/l] [select] |
by callmeavis (Novice) on Aug 27, 2010 at 18:26 UTC | |