Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: parsing system info

by 5mi11er (Deacon)
on May 27, 2008 at 16:54 UTC ( [id://688695]=note: print w/replies, xml ) Need Help??


in reply to parsing system info

Excellent suggestion to use the /proc system grep.

But as a training exercise for me, (I wasn't very clear initially), I'm looking for how to parse the different areas. Pseudo-code time:

while(<>) {
   # search for lots of dashes, that separates the server records
       #once we have found that, we're at step 1
   # Step 1
       # gather server name/main ip address
       # if we find "ifconfig" go to step 2
   # Step 2
       # gather IP address info
       # if we find "uname" to to step 3
   # Etc...
}
That's my current, probably bad, idea of how to tackle the problem. I'm pretty sure there are much better ways of going about it...

-Scott

Replies are listed 'Best First'.
Re^2: parsing system info
by Narveson (Chaplain) on May 27, 2008 at 17:22 UTC
    Little utilities each parsing one set of information is how the "tools" do it, but that doesn't help me learn more about parsing larger things such as this.

    I'd say develop little utilities each parsing one set of information.

    You are planning a big utility that opens your data file once and reads everything. Instead, let each little utility open the file, scan through for what it needs, and ignore everything it doesn't know about. That way you can build and test one little piece at a time.

    After you've written several little utilities, you'll find they all use some of the same tricks, e.g. the regex for reading the server name. You will want to put these repeated snippets into a module that each little utility can use. Do that module later. Start by building some little thing that works right now.

    For example, the df request returns a table with column headings. Have a little utility that handles this.

    # regexes referenced below should be defined or imported here # hash of hashes summarizing df results my %partitions_on; LINE: while (<>) { # pull the server name from a line like [jboss-box1] my ( $server ) = /$SERVER_PATTERN/; next LINE if !$server; # skip what doesn't relate to the df command NON_DF_INFO: while (<>) { last NON_DF_INFO if /$DF_PATTERN/; } my $header = <>; my @cols = split; my %value_of; DATA: while (<>) { last DATA if /$BLANK/; @value_of{@cols} = split; } %partitions_on{$server} = \%value_of; # go back to hunting for another server next LINE; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://688695]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-18 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found