On 10/19/07, Juan B <[EMAIL PROTECTED]> wrote: > I need a script to read /var/log messages and each > time it sees a line with the word "IDS" it will send > the whole line via mail to the administrator
> #!/usr/local/bin/perl > > $file = '/var/log/messages'; # Name the file > open(INFO, "/var/log/messages"); # Open the file > > while > $message = <INFO> / IDS/g { # Read it > into an array > $ message = $& It started out as a Perl program, but something bad happened to it. What array is the comment misleading us about? The syntax for a while loop is covered in the perlsyn manpage. > sub sendEmail # simple Email function > > my $sendmail = '/usr/lib/sendmail'; > open(MAIL, "|$sendmail -oi -t"); > print MAIL "From: [EMAIL PROTECTED]"; > print MAIL "To: [EMAIL PROTECTED]"; Well, this looks like you copied it from somebody else. Nothing wrong with that, although there are better ways than piping to sendmail. But if you had turned on warnings, Perl would have warned you about putting those e-mail addresses in double-quotes. You don't really have an array named @hpda, do you? > It doesnt work and I dont know why... can someone > help? You can ask Perl to help you diagnose your problems by asking for warnings. Most people recommend that each program have these lines near the start: use strict; use warnings; When you get a message that you can't fix, find advice about it in the perldiag manpage. > another question, how to execute this script so it > will be in memory oc the server all the time? should I > run it throw rc.local? No! Not until it's debugged, at least. But staying in memory seems excessive. In any case, your administrator doesn't want to get each message by e-mail the very instant it appears, because that would require each line to be sent in its own e-mail message, giving the administrator perhaps thousands of messages during a crisis (and, possibly, causing a crisis of its own). It sounds more like a cron task to me; your program should send a batch of new entries as a single message (if needed) whenever it wakes up, and you can easily configure it to wake up every 30 minutes, or whatever. Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/