Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl to parse out iostat information on solaris 9

Reply
Thread Tools

perl to parse out iostat information on solaris 9

 
 
inetquestion
Guest
Posts: n/a
 
      08-08-2007
For the program below why are all 4 attributes not getting filled in.
The data seems to be coming across per the Debug statement...

btw - I am running this on solaris 9. The problem seems to be related
to the whitespace at the beginning of the line, but I thought the
regex should account for it...

-Inet

#!/usr/bin/perl

chomp($CPU=`iostat -c 1 2 | tail -1`);
($usrcpu,$syscpu,$wiocpu,$idlecpu) = split(/\s+/,$CPU);

print "DEBUG: $CPU\n";
print "usrcpu: $usrcpu\n";
print "syscpu: $syscpu\n";
print "wiocpu: $wiocpu\n";
print "idlecpu: $idlecpu\n";

 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      08-09-2007
inetquestion <> wrote:

> For the program below why are all 4 attributes not getting filled in.
> The data seems to be coming across per the Debug statement...



What is "the Debug statement"?


> btw - I am running this on solaris 9.



If you show what the data looks like, then even people who are not
on Solaris could attempt to help you.

I have no idea what the output of iostat looks like.


> The problem seems to be related
> to the whitespace at the beginning of the line,



Then one solution would be to remove the whitespace at the beginning
of the line before split()ting the string.

$CPU =~ s/^\s+//;


> but I thought the
> regex should account for it...



The 2nd sentence of the documentation for the function you are using says:

By default, empty leading fields are preserved

You have an empty leading field.


> ($usrcpu,$syscpu,$wiocpu,$idlecpu) = split(/\s+/,$CPU);



Another solution would be to discard the empty leading field:

(undef, $usrcpu, $syscpu, $wiocpu, $idlecpu) = split(/\s+/, $CPU);


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
 
 
 
inetquestion
Guest
Posts: n/a
 
      08-09-2007
Tad,

The output for the debug line appears as follow:

DEBUG: 1 2 3 94

As you mentioned using a 5th variable or trimming the leading space
would work. I guess I got caught up thinking that regex should do the
job with no further modification needed. Is there another one I could
have used instead which would dump leading spaces?

-Inet

 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      08-09-2007
Tad McClellan <> wrote in comp.lang.perl.misc:
> inetquestion <> wrote:


[...]

> I have no idea what the output of iostat looks like.


Nor do I.

>
> > The problem seems to be related
> > to the whitespace at the beginning of the line,

>
>
> Then one solution would be to remove the whitespace at the beginning
> of the line before split()ting the string.
>
> $CPU =~ s/^\s+//;


[...]

> Another solution would be to discard the empty leading field:
>
> (undef, $usrcpu, $syscpu, $wiocpu, $idlecpu) = split(/\s+/, $CPU);


That is only a solution if the empty field is guaranteed to be present.
Since we don't know the format of the line, that's not a given.

Anno
 
Reply With Quote
 
Josef Moellers
Guest
Posts: n/a
 
      08-09-2007
wrote:
> Tad McClellan <> wrote in comp.lang.perl.misc:


>
>>Another solution would be to discard the empty leading field:
>>
>> (undef, $usrcpu, $syscpu, $wiocpu, $idlecpu) = split(/\s+/, $CPU);

>
>
> That is only a solution if the empty field is guaranteed to be present.
> Since we don't know the format of the line, that's not a given.


In these circumstances (parsing /proc/interrupts on a Linux machine),
I've done it like this:

my @f = split(/\s+/, $line);
shift @f unless length $f[0];

Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unraveling binary data out of the proc filesystem on Solaris Daniel Berger Ruby 12 08-29-2008 02:25 PM
optparse: parse v. parse! ?? 7stud -- Ruby 3 02-20-2008 05:20 AM
How to parse the log file to get useful information using perl or shell? robertchen117@gmail.com Perl Misc 1 03-26-2007 09:54 AM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM
Load information in Solaris (Perl Script.) Alice Stamp Perl Misc 3 11-05-2004 01:33 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57