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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.