aixmike has asked for the wisdom of the Perl Monks concerning the following question:

I am an AIX admin. I have sar creating a summary file which created the text below. I would like to create a report from the file suitable for display in html format with anchor tags for each section. I have tried the following but the format is unacceptable.
_____________________________________________ #!/usr/bin/perl # # open (SAR,">/usr/local/htdocs/SAR/sar.out.html"); while (<>) { print SAR $_,"\n<br>" ; } _____________________________________________ The file is in this format : ------------------------------------- AIX beips88 2 5 000C79AF4C00 04/27/05 System Configuration: lcpu=6 11:30:42 %usr %sys %wio %idle 13:19:00 0 0 0 100 14:19:00 0 0 0 100 15:19:01 0 0 0 100 16:19:00 0 0 0 100 17:19:00 0 0 0 100 Average 0 0 0 100 System Configuration: lcpu=6 11:30:42 bread/s lread/s %rcache bwrit/s lwrit/s %wcache pread/s pwrit +/s 13:19:00 0 0 0 0 0 0 0 + 0 14:19:00 0 0 0 0 0 0 0 + 0 15:19:01 0 0 0 0 0 0 0 + 0 16:19:00 0 0 0 0 0 0 0 + 0 17:19:00 0 0 0 0 0 0 0 + 0 Average 0 0 0 0 0 0 0 + 0 System Configuration: lcpu=6 11:30:42 scall/s sread/s swrit/s fork/s exec/s rchar/s wchar/s 13:19:00 73 8 3 0.22 0.26 8646 643 14:19:00 17 3 1 0.02 0.01 1552 31 15:19:01 29 4 2 0.05 0.05 6839 194 16:19:00 27 5 2 0.03 0.03 2390 157 17:19:00 11 2 0 0.00 0.00 1124 3 Average 25 4 1 0.04 0.04 3412 138 System Configuration: lcpu=6 11:30:42 cswch/s 13:19:00 59 14:19:00 54 15:19:01 58 16:19:00 59 17:19:00 54 Average 57 System Configuration: lcpu=6 11:30:42 rawch/s canch/s outch/s rcvin/s xmtin/s mdmin/s 13:19:00 1 0 6 0 0 0 14:19:00 0 0 4 0 0 0 15:19:01 1 0 12 0 0 0 16:19:00 1 0 20 0 0 0 17:19:00 0 0 0 0 0 0 Average 0 0 9 0 0 0 System Configuration: lcpu=6 11:30:42 iget/s lookuppn/s dirblk/s 13:19:00 0 7 1 14:19:00 0 1 0 15:19:01 0 2 0 16:19:00 0 1 0 17:19:00 0 1 0 Average 0 2 0 System Configuration: lcpu=6 11:30:42 runq-sz %runocc swpq-sz %swpocc 13:19:00 1.3 1 1.0 0 14:19:00 1.0 0 1.0 0 15:19:01 1.0 0 1.1 0 16:19:00 1.1 0 1.0 0 17:19:00 1.0 0 Average 1.2 0 1.0 0 System Configuration: 11:30:42 proc-sz inod-sz file-sz thrd-sz 13:19:00 66/262144 350/3018 424/511 200/524288 14:19:00 72/262144 355/3413 438/511 206/524288 15:19:01 72/262144 357/3479 441/511 206/524288 16:19:00 68/262144 350/3523 425/511 202/524288 17:19:00 68/262144 350/3526 425/511 202/524288 System Configuration: lcpu=6 11:30:42 msg/s sema/s 13:19:00 0.05 0.00 14:19:00 0.01 0.00 15:19:01 0.01 0.00 16:19:00 0.01 0.00 17:19:00 0.01 0.00 Average 0.01 0.00 ----------------------------
Thanks in advance

Replies are listed 'Best First'.
Re: Display Results
by jpeg (Chaplain) on Apr 28, 2005 at 17:19 UTC
    Yes, getting a nicely formatted report usually takes more effort than adding a break tag at the end of the line. That said, this looks like a pretty easy task.

    Offhand, I would

    • examine the start of $_ for a digit or uppercase character.
    • If it's an uppercase char, split on : and write a table tag
    • until the next uppercase char, split on whitespace and stick them in tr/td cells.
    • check for another line beginning with an uppercase char without a colon in it, or calculate the averages yourself.

    Hope this helps.
    --
    jpg

Re: Display Results
by tcf03 (Deacon) on Apr 28, 2005 at 17:52 UTC
    aixmike
    Im not sure exactly what your end goal is, but for AIX have you tried using nmon, rrdtool, and nmon2rrd. If all you need are performance stats why reinvent the wheel? Or if you just want what you have try perldoc CGI. That might be more of what youre looking for.
    The code below is simplistic, but might get you off on the right foot.
    If its on a local box ie not on the internet, Id just run this from /cgi-bin/.
    #!/usr/bin/perl -w use strict; use CGI qw/:standard/; print header; print start_html; my @SAR=qx/sar/; for (@SAR) { print } print end_html;
    Ted
    --
    "Men have become the tools of their tools."
      --Henry David Thoreau
      This is quick and easy, but produces the same results. It is just UNformatted test in a browser.
      AIX beips88 2 5 000C79AF4C00 04/28/05 System Configuration: lcpu=6 07: +59:00 %usr %sys %wio %idle 08:19:00 0 0 0 100 08:39:00 0 0 0 100 08:5 +9:00 0 0 0 100 09:19:00 0 0 0 100 09:39:00 0 0 0 100 09:59:00 0 0 0 1 +00 10:19:00 0 0 0 100 10:39:00 0 0 0 100 10:59:00 0 0 0 100 11:19:00 +0 0 0 100 11:39:00 0 0 0 100 11:59:00 0 0 0 100 12:19:00 0 0 0 100 12 +:39:00 0 0 0 100 12:59:00 0 0 0 100 13:19:00 0 0 0 100 13:39:00 0 0 0 + 100 13:59:00 0 0 0 100 14:19:00 0 0 0 100 14:39:00 0 0 0 100 Average + 0 0 0 100
Re: Display Results
by Transient (Hermit) on Apr 28, 2005 at 16:43 UTC
    What defines a section. What do you want the anchor tags to be? What are the keywords and start and/or end a section?
      The "system Configuration" defines the beginning and the end of the line "Average" defines the ending of the section. As for the anchor tags, they can be anything, but I started with sepc1 ... spec# Thanks
Re: Display Results
by Transient (Hermit) on Apr 29, 2005 at 12:20 UTC
    #!/usr/bin/perl use strict; my $file = "/usr/local/htdocs/SAR/sar.out.html"; open (SAR,">$file") or die "Unable to open $file!\n$!\n"; my $out = ""; my $header_count = 0; while (<DATA>) { # search for header, you could also use substr s!^(System Configuration:)!qq{<a name="spec}.++$header_count.qq{">$1 +</a>}!e; $out .= $_."<br>\n"; } my $header = ""; $header = $header.qq{ <a href="#spec$_">Spec $_</a><br>\n } foreach 1. +.$header_count; print SAR $header."\n<hr>\n".$out; close(SAR);