Mauro wrote:
I have to assign output of
ssh [EMAIL PROTECTED] sar -u 1 1|awk '/%usr    %sys    %wio   %idle/ {
getline ; printf "%i %i %i %i", $2, $3, $4, $5 }'
to an array.
The output looks like:
0 0 0 100
if I did:
my @pippo=qx'ssh [EMAIL PROTECTED] sar -u 1 1|awk \'/%usr    %sys    %wio
%idle/ { getline ; printf "%i %i %i %i", $2, $3, $4, $5 }\'';
it assigns the entire output to $pippo[0] instead of to give each number in
output to a differenet array element.
Please can you give me any hints?

You could probably do it something like this (UNTESTED):

open PIPE, 'ssh [EMAIL PROTECTED] sar -u 1 1 |'
    or die "Cannot open pipe from ssh: $!";

my @pippo;
while ( <PIPE> ) {
    next unless /%usr    %sys    %wio   %idle/;
    push @pippo, ( split ' ', <PIPE> )[ 1 .. 4 ];
    }

close PIPE
    or warn $! ? "Error closing ssh pipe: $!"
               : "Exit status $? from ssh";



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to