HI,

My name is juan. im totally new with perl...

Im trying to write a script which will read from /var/log/messages and send a mail each time a line with the word IDS is found. I want that the whole line will be sended by mail:

this is what I wrote:

#!/usr/local/bin/perl # # Program to check /var/log/messeges for alerts contining the word IDS + and send mails # in case the word is found- including the line use strict; use warnings; use Mail::Mailer; open (INFO, "/var/log/messages"); # Open the file while { @message = <INFO> / IDS/g # Read it into an array @message = $& $mailer = Mail::Mailer->new("smtp", "10.83.27.71"); $mailer->open( 'From' => 'Syslog <syslog@hpda.com.ar>', 'To' => 'gabriela pinado <gabriela.pinado@hpda.com +.ar>', 'Subject' => 'PiX Detected Attack ' ); print $mailer <<@message; close($mailer) or die "can't close mailer: $!";
when I execute the script I get this:
[root@juanlinux perl]# perl ./logcheck Array found where operator expected at ./logcheck line 14, at end of l +ine (Do you need to predeclare g?) Scalar found where operator expected at ./logcheck line 16, near "$& $mailer" (Missing semicolon on previous line?) Use of bare << to mean <<"" is deprecated at ./logcheck line 20. Array found where operator expected at ./logcheck line 22, at end of l +ine (Might be a runaway multi-line << string starting on line 20) (Missing operator before ?) syntax error at ./logcheck line 13, near "{" Global symbol "@message" requires explicit package name at ./logcheck +line 13. Global symbol "@message" requires explicit package name at ./logcheck +line 14. Global symbol "$mailer" requires explicit package name at ./logcheck l +ine 16. Global symbol "$mailer" requires explicit package name at ./logcheck l +ine 17. Global symbol "$mailer" requires explicit package name at ./logcheck l +ine 20. Global symbol "$mailer" requires explicit package name at ./logcheck l +ine 20. syntax error at ./logcheck line 22, near "@message" Global symbol "@message" requires explicit package name at ./logcheck +line 22. Execution of ./logcheck aborted due to compilation errors.
I get so much errors and I dont know how to hendle them... please give me a hend !!!

thanks a lot for your time and help!

Juan


In reply to pattern matching and sending mail! by juanb007

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.