[Buffalo-pm] Asterisk Wildcard When Running CommandviaExec...

DANIEL MAGNUSZEWSKI dmagnuszewski at mandtbank.com
Fri Jul 7 07:54:03 PDT 2006


That didn't return anything for me, but I changed it around to:

open( PROGRAM, '-|') or exec('/bin/grep', $host, glob
'/var/adm/messages*');

...and it worked! I had to break the open apart with exec (similar to
how it was before). I wonder if it was a matter of the single and double
quotes after glob?

Thanks for the help!

-Dan

>>> "Ben. B." <bennymack at gmail.com> 07/06/06 5:19 PM >>>
Hey,

I got it to work on a linux server with this line:
open( PROGRAM, '-|', '/bin/grep', $host, glob '/var/adm/messages*' );

The open or foreach was coming up as a syntax error too.

I had to print the values directly because the regex was failing but
it worked otherwise.

Let me know if that works for ya.

Ben

On 7/6/06, DANIEL MAGNUSZEWSKI <dmagnuszewski at mandtbank.com> wrote:
> Here it is:
>
> #!/usr/bin/perl
> use strict;
>
> $|++;
>
> use CGI;
> my $cgi = new CGI;
>
> if (!$cgi->param)
> {
>         print_header();
>         print_default_page();
>         print_end_html();
> }
> elsif ($cgi->param('host') =~ /^[\w\d\-]+$/)
> {
>         get_syslog_data(lc($cgi->param('host')));
>         print "<P>";
>         print_default_page();
>         print_end_html();
> }
> else
> {
>         my $msg = '<b> ' . $cgi->param('host') . '</b> ' . " Is An
> Incorrect Hostname! " . '<p>';
>         print_error_page($msg);
>         print_end_html();
> }
>
> ###############
> # SUBROUTINES #
> ###############
>
> sub get_syslog_data
> {
>         my $host = shift;
>         my $color = 0;
>         my @color = qw(FFFFCC white);
>
>         open (PROGRAM, "-|")
>                 or foreach (glob "/var/adm/messages*") { exec
> ("/bin/grep", "$host", "$_") };
>                 # or exec ("/bin/grep $host /var/adm/messages*");
>                 # or exec ("/bin/grep", "$host",
"/var/adm/messages");
>
>         print "PROGRAM Length: " . length(<PROGRAM>);
>
>         if (length(<PROGRAM>) == 0)
>         {
>                 print "LINE: $_";
>                 print_header();
>                 print '<FONT COLOR="red">There are no syslog
messages
> for <b>' . $host . '</b>! </FONT><p>';
>                 print_default_page();
>                 exit;
>         }
>         else { print_header(); }
>
>         print $cgi->start_table({-border=>'1', -cellpadding=>'3',
> -bgcolor=>'gray'});
>         print $cgi->Tr({-align=>'left', -bgcolor=>'66CCFF'},
> [$cgi->th(['Time', 'Device', 'Syslog Message'])]);
>
>         while (<PROGRAM>)
>         {
>                 if ($color == 1) { $color--; }
>                 else                   {$color++; };
>
>
>
/:([A-Za-z]{3}\s{1,2}\d{1,2}\s\d+\:\d+\:\d+)\s([\w\d\-]+\.[\w\d\-]+\.[\w\d\-]+)\s(.+)$/;
>
>                 print $cgi->Tr({-align=>'left',
> -bgcolor=>"$color[$color]"}, [$cgi->td(["$1", "$2", "$3"])]);
>         }
> }
>
> sub print_header
> {
>         print $cgi->header;
>         print $cgi->start_html("M&T Bank - Syslog Report
Generator");
> }
>
> sub print_default_page
> {
>         print "Enter The Device's Name: ";
>         print $cgi->start_form();
>         print $cgi->textfield(
>                 -name=>'host',
>                 -size=>25,
>                 -maxlength=>80
>         );
>         print $cgi->p;
>         print $cgi->submit(-value=>'Find Syslogs');
>         print $cgi->end_form();
>
> }
>
> sub print_error_page
> {
>         my $error_msg = shift;
>         print_header();
>         print '<FONT COLOR="red">ERROR: ' . $error_msg . '</FONT>';
>         print_default_page();
>         print_end_html();
> }
>
> sub print_end_html
> {
>         print $cgi->end_html;
> }
>
>
>
> >>> "Ben. B." <bennymack at gmail.com> 07/06/06 4:39 PM >>>
> I'm pretty much stumped. Maybe it's something in the surrounding
> program. Do you mind pasting all the code?
>
> Ben
>
>
>
>




More information about the Buffalo-pm mailing list