in reply to File Search

This is the Perlmonks, so we'll do a version in Perl (not thoroughly tested):
use strict; use warnings; use File::Find; use Mail::Send; my $curtime = time(); find(\&wanted, qw(/home/arjen/test)); sub wanted { # Warning: the ctime field is not really the creation time! # See perlport (File and Filesystems) return if (($curtime - (stat($File::Find::dir))[10])) > 900; return if $_ !~ /\.out$/; open(FILE, "<$_") or die "Cannot open $_: $!\n"; while (my $line = <FILE>) { last if $line =~ /error/; } close(FILE); my $msg = Mail::Send->new(Subject => "Error found!", To => "operator\@datacenter"); my $fh = $msg->open(); print $fh "We found an error in $_!\n"; $fh->close(); print "Mail sent\n"; }

Arjen

Replies are listed 'Best First'.
Re: Re: File Search
by mikevanhoff (Acolyte) on Oct 27, 2003 at 17:25 UTC
    I am using a subset of your suggestion, but am getting an error when trying to open the file to read it.
    use File::Find; find(\&wanted, '/opt/psoft/hr83tst/appserv/prcs/HRTST/log_output/'); print $_ ; sub wanted { return unless /\.out$/; open F, $_ or return ; while (defined (my $line = <F>)) { if (-M $_ < 0.5) { print $_ if $line =~ /error/ ; system("mail -s' $_' mikev\@beverlycorp.com<$line"); return; } } close F; }
    This is teh error being returned - "A file or directory in the path name does not exist. sh: error: 0403-016 Cannot find or open the file." Any help is greatly appreciated.
      sh: error: 0403-016 Cannot find or open the file
      It looks like the system command goes wrong, or more specifically, the shell which is started by system can't start the mail program. Is the directory where mail is located in your PATH? Does the mail program even exist?

      Arjen

        Yes the mail command is in the path, and yes it exists. I have attempted to preface the command with the full path ie /usr/bin/mail, but recieved the same error message.