#!/usr/bin/perl -w use strict; # 'global' variable declarations go here my $bgcolor= "silver"; my $fontcolor = "white"; my $headcolor = "#33ccff"; my $linkcolor = "red"; my $outpath = "/var/www/html"; my $msg = "/var/log/messages"; my %messages; my %msgbydate; my $tempcounter; my %flag; my $key; my $date; my %number = ( "Jan" => "1", "Feb" => "2", "Mar" => "3", "Apr" => "4", "May" => "5", "Jun" => "6", "Jul" => "7", "Aug" => "8", "Sep" => "9", "Oct" =>"10", "Nov" =>"11", "Dec" =>"12"); open (MESSAGELOG,$msg) or die "failed to open $msg: $!\n"; while (<MESSAGELOG>) { my ($month,$day,$time,$host,$service,undef) = split; $date = $number{$month}."-".$day; # strip out anything between non word characters (basically looking + to eliminate pids) $service =~s/(\W[\d\w\W]+\W)//g; $service =~s/://g; # print "- $service\n"; $messages{$service}++; $msgbydate{$date}++; unless ($service=~m/--/) {&writefile ($flag{$service},$service,$_) +;} $flag{$service} = 1; &writefile ($flag{$date},$date,$_); $flag{date}=1; } close MESSAGELOG; my $outfile = $outpath ."/messages.html"; open (TEMPOUT,">$outfile") or die "failed to open $outfile: $!\n"; print TEMPOUT <<"END"; <html> <body> <table bgcolor=silver text=white link=white border=1> <tr> <td colspan=2 bgcolor=#33ccff text=white> <b>Message Log Viewer</b> </td> </tr><tr> <td bgcolor=$bgcolor text=$fontcolor> <a href="messageservices.html">by service</a> </td> <td bgcolor=$bgcolor text=$fontcolor> <a href="messagedates.html">by date</a> </td> </tr> </table> </body> </html> END close TEMPOUT; $outfile = $outpath ."/messageservices.html"; open (TEMPOUT,">$outfile") or die "failed to open $outfile: $!\n"; print TEMPOUT <<"END"; <html> <body> <h1>Summary of $msg</h1> <br> <table> <tr> <td> <table bgcolor=$bgcolor text=$fontcolor link=$linkcolor border=1> <tr> <td bgcolor=$headcolor text=$fontcolor>Service</td> <td bgcolor=$headcolor text=$fontcolor># of Msgs</td> </tr> END foreach $key (sort keys %messages) { unless ($key=~m/--/) { print TEMPOUT "<tr><td bgcolor=$bgcolor text=$fontcolor>$key</ +td><td><a href=$key.html>$messages{$key}</a></td></tr>"; } } print TEMPOUT <<"END"; </table> </td> </tr> </table> </body> </html> END close TEMPOUT; $outfile = $outpath."/messagedates.html"; open (TEMPOUT,">$outfile") or die "failed to open $outfile: $!\n"; print TEMPOUT <<"END"; <html> <body> <h1>Summary of $msg</h1> <br> <table> <tr> <td valign=top> <table bgcolor=$bgcolor text=$fontcolor link=$linkcolor border=1> <tr> <td bgcolor=$headcolor text=$fontcolor>Date</td> <td bgcolor=$headcolor text=$fontcolor># of Msgs</td> </tr> END foreach $key (sort keys %msgbydate) { print TEMPOUT "<tr><td bgcolor=silver text=white>$key</td><td><a h +ref=$key.html>$msgbydate{$key}</a></td></tr>"; } print TEMPOUT <<"END"; </table> </table> </body> </html> END close TEMPOUT; sub writefile { my $flag = $_[0]; my $label = $_[1]; my $line = $_[2]; unless ($flag) { open(TEMPOUT,">".$outpath."/".$label.".html") or die "failed t +o open $date: $!\n"; $flag{$date}=1; } else { open(TEMPOUT,">>".$outpath."/".$label.".html") or die "failed +to open $date: $!\n"; } print TEMPOUT $line; print TEMPOUT "<br>"; close TEMPOUT; }

In reply to Linux message log webifier by hans_moleman

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.