Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi all,

I find myself spinning at the moment. I want to create a nice report about ~40 servers that includes ip address usage, memory free/avail, drive size, and partition size/used/free information.

To this end I have a quick and dirty little shell script, along with some sudoers entries spread across the servers such that I can kick off a 'go gather the info' script and have it finish less than 1 minute later.

Already I hear the cries of "Why are you rolling your own? MRTG, RRDTool, Nagios, etc. do that and more for you!" You're absolutely right, and I'm heading down that path already. However, that doesn't teach me any cool new skills that could come in handy down the road.

So, my question is this. How does one parse this type of data in a way that is readable, maintainable, and extensible? A sample of my datafile:

-------------------------------------------------------------
[jboss-box1]
$ echo `hostname -i; hostname -f`
10.1.9.183 jboss-box1.domain.com
$ /sbin/ifconfig | grep -E '(encap|addr)'
eth0      Link encap:Ethernet  HWaddr 00:0C:29:3D:6B:CF  
          inet addr:10.1.9.183  Bcast:10.1.9.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe3d:6bcf/64 Scope:Link
          Interrupt:177 Base address:0x1424 
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host

$ uname -a
Linux jboss-box1 2.6.9-67.0.7.ELsmp #1 SMP Sat Mar 15 06:54:55 EDT 2008 i686 i686 i386 GNU/Linux

$ cat /etc/redhat-release
CentOS release 4.6 (Final)

$ free -b
             total       used       free     shared    buffers     cached
Mem:    1059393536 1035771904   23621632          0   92483584  718749696
-/+ buffers/cache:  224538624  834854912
Swap:   2146754560          0 2146754560

$ sudo /sbin/fdisk -l | grep : 
Disk /dev/sda: 42.9 GB, 42949672960 bytes

$ df -aP -t ext2 -t ext3
Filesystem         1024-blocks      Used Available Capacity Mounted on
/dev/sda2             36638508   2750768  32026612       8% /
/dev/sda1               505604     22994    456506       5% /boot
/dev/sda3              2063536   1291852    666860      66% /var/log

-------------------------------------------------------------
[jboss-box2]
$ echo `hostname -i; hostname -f`
10.1.9.182 jboss-box2.domain.com

$ /sbin/ifconfig | grep -E '(encap|addr)'
eth0      Link encap:Ethernet  HWaddr 00:0C:29:D6:56:4C  
          inet addr:10.1.9.182  Bcast:10.1.9.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fed6:564c/64 Scope:Link
          Interrupt:177 Base address:0x1424 
eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:D6:56:4C  
          inet addr:10.1.9.187  Bcast:10.1.9.255  Mask:255.255.255.0
          Interrupt:177 Base address:0x1424 
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host

$ uname -a
Linux jboss-box2 2.6.9-67.0.7.ELsmp #1 SMP Sat Mar 15 06:54:55 EDT 2008 i686 i686 i386 GNU/Linux

$ cat /etc/redhat-release
CentOS release 4.6 (Final)

$ free -b
             total       used       free     shared    buffers     cached
Mem:    1059393536 1037778944   21614592          0   88453120  686907392
-/+ buffers/cache:  262418432  796975104
Swap:   2146754560     212992 2146541568

$ sudo /sbin/fdisk -l | grep : 
Disk /dev/sda: 42.9 GB, 42949672960 bytes

$ df -aP -t ext2 -t ext3
Filesystem         1024-blocks      Used Available Capacity Mounted on
/dev/sda2             36638508   2789720  31987660       9% /
/dev/sda1               505604     22994    456506       5% /boot
/dev/sda3              2063536   1196952    761760      62% /var/log

-------------------------------------------------------------
[db-box1]
$ echo `hostname -i; hostname -f`
10.1.9.181 db-box1.domain.com

$ /sbin/ifconfig | grep -E '(encap|addr)'
eth0      Link encap:Ethernet  HWaddr 00:0C:29:98:96:41  
          inet addr:10.1.9.181  Bcast:10.1.9.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe98:9641/64 Scope:Link
          Interrupt:177 Base address:0x1424 
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host

$ uname -a
Linux db-box1 2.6.9-67.0.7.ELsmp #1 SMP Sat Mar 15 06:54:55 EDT 2008 i686 i686 i386 GNU/Linux

$ cat /etc/redhat-release
CentOS release 4.6 (Final)

$ free -b
             total       used       free     shared    buffers     cached
Mem:    2124685312 2087546880   37138432          0   41418752 1901887488
-/+ buffers/cache:  144240640 1980444672
Swap:   2146754560  430018560 1716736000

$ sudo /sbin/fdisk -l | grep : 
Disk /dev/sda: 107.3 GB, 107374182400 bytes

$ df -aP -t ext2 -t ext3
Filesystem         1024-blocks      Used Available Capacity Mounted on
/dev/sda2             98564748  28245568  65312124      31% /
/dev/sda1               505604     22991    456509       5% /boot
/dev/sda3              2063536     42116   1916596       3% /var/log
I've done lots of simple parsing before, but rolling my own here seems to be a lot of work and the wrong approach. I've searched for parsing examples, but thus far, they are just beyond my grasp for me to understand how to bend them to work with this type of data. 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.

Can any of the parsing guru's help me get up to speed?

Thank you,

-Scott


In reply to parsing system info by 5mi11er

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2021-10-24 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?