Perl or Shell Script to read files

Could anyone please help me with the code snippet for the below logic.

 Need to grep a file from the path "/usr/qa/qaout.log' and open  and read  the file to grep for words like Error, Permission Denied, Could not send, No such file or directory.

If it encounters any one of these word it needs to send and  email with this log file as an attachment.

Who is Participating?
Bryan ButlerCommented:
How about:
#!/usr/bin/perl -w
use strict;

sub send_me_email {
  use MIME::Lite;

  my $msg = MIME::Lite->new(
    From    => '',
    To      => '',
    Cc      => ',',
    Subject => 'Log file attached...',
    Type    => 'multipart/mixed',

      Type     => 'TEXT',
      Data     => "Here's the Log file",

    Type     => 'image/gif',
    Path     => 'aaa000123.gif',
    Filename => 'logo.gif',


open (TEXTFILE, '/usr/qa/qaout.log');
$_ = join('',<TEXTFILE>);
close (TEXTFILE)

while (<>) {
  send_me_email if /Error|Permission Denied|Could not send/;

Open in new window

Bryan ButlerCommented:
    Type     => 'image/gif',
    Path     => 'aaa000123.gif',
    Filename => 'logo.gif',

 should be:

    Type     => 'text',
    Path     => '/usr/qa',
    Filename => 'qaout.log',

Assuming you have mutt (there are plenty of alternatives)

egrep -qi "error|permission denied|could not send|no such file or directory" $LOG && mutt -a $LOG -s "Subject line"

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.