Re: CGI grep

2004-09-09 Thread $Bill Luebkert
Larry Linskey wrote:
 Hi,  I have been only working with perl for a few weeks now.
 
  
 
  I am wondering if anyone has a cgi script that I could post on a
 website that would allow users to grep files for a string.  I am
 constantly parsing smtp logs for users that did not receive an email . 
 I would love to offer such a tool to our support desk.

That's pretty simple stuff really.  On UNIX, it would be simpler to
run a grep on the files externally and return the results.  On Doze,
you could do the same using findstr (if you have it on your flavor
of Doze) or use File::Find and slurp and grep the files one at a time
in your script.

-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--  o // //  Castle of Medieval Myth  Magic http://www.todbe.com/
-/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: CGI grep

2004-09-09 Thread Peter Eisengrein



The short answer is, yes, perl is great for this kind of tast. Now, 
specifically, you want to have the user input a string and then match for it in 
the files in the mailq? Or, perhaps the string is their email 
address?

However you want to address it, the logic will be pretty much the 
same:

### untested and without the cgi stuff
opendir(DIR,$dir) || die "can't open $dir for reading : 
$!\n";
my @files = readdir(DIR);
close(DIR);

my $string = "whatever you want to match here"; # get this from the 
CGI?

foreach my $file(@files)
{
 open(FILE,$file) ||{warn "Can't open $file for 
reading : $!\n"; next;}
 foreach my $line(FILE)
 {
 
if ($line =~ 
/$string/i)
 
{
 
print "$file MATCHES!!!\n"; # or 
whatever you wish to do with this
 
}
 }
 close(FILE);
}

### end

Try it out and ask the group if you need help.


  -Original Message-From: Larry Linskey 
  [mailto:[EMAIL PROTECTED]Sent: Thursday, September 09, 2004 
  10:09 AMTo: 
  [EMAIL PROTECTED]Subject: CGI 
  grep
  
  Hi, I have been only working 
  with perl for a few weeks now. 
  
  I am wondering if anyone has 
  a cgi script that I could post on a website that would allow users to grep 
  files for a string. I am constantly parsing smtp logs for users that did 
  not receive an email . I would love to offer such a tool to our support 
  desk.
  
  Thanks in 
  advance,
  Larry Linskey
  
  
  
  
  
  
  This message was scanned by GatewayDefender10:13:10 AM ET - 
9/9/2004
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: CGI grep

2004-09-09 Thread Peter Eisengrein



oh yeah, one thing I should've added to boost speed. If you found a match 
no need to keep looking, thus add the last statement


   
  if ($line =~ 
  /$string/i)
   
  {
   
  print "$file 
  MATCHES!!!\n"; # or whatever you wish to do with this
  last;
   
  }
  
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs