-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 05-Nov-2002/04:07 -0500, RH <[EMAIL PROTECTED]> wrote: >But in this case I will receive messages not once, but periodically. Is >there a way, to get mail if it got down, and the next mail when the T1 >line becomes Up and so on. In other words I need a mail message when the >Line status is changed, but not a massages with the same T1 line status.
The best way to do this would be to have the application itself call a script when the status changes. Having a script check the logfile every few minutes would work, but would probably require reading the entire logfile each time. The following script is a good faith effort, but has not been tested. #!/usr/bin/perl # # Check logfile for a status changes that occured after the last check. # # Specify the name of the log file. $logfile = '/var/log/programname.log'; # Who gets the email reports. $recipient = '[EMAIL PROTECTED]'; # Get the date/time of the last time the script was run, using the same # format as is used in the logfile. This example assumes the script was # last run 5 minutes ago and that the time is in the Apache logfile time # format. The extra 2 seconds is designed to give a little overlap so # that no entries are missed. $lastdate = `date -d '5 min 2 sec ago' +%d/%b/%Y:%H:%M:%S`; chomp $lastdate; # Read the log file and check the most recent lines for status changes. open(LOGFILE,"$logfile"); while ($line = <LOGFILE>) { if ($lastdate lt $line) { # do nothing } elsif ($line =~ /line is up/) { chomp $line; push(@statuschanges,$line); } elsif ($line =~ /line is down/) { chomp $line; push(@statuschanges,$line); } } close(LOGFILE); # If there are any status changes, send an email notice. $statuscount = @statuschanges; if ($statuscount > 0) { open(MAIL,'|/bin/mail -s "Line status changes" $recipient'); print MAIL "These status changes have been recorded in $logfile\n"; print MAIL "since $lastdate):\n\n"; foreach $statusline (@statuschanges) { print MAIL "$statusline\n"; } close(MAIL); } exit; Tony - -- Anthony E. Greene <mailto:Anthony%20E.%20Greene%20%3Cagreene@;pobox.com%3E> OpenPGP Key: 0x6C94239D/7B3D BD7D 7D91 1B44 BA26 C484 A42A 60DD 6C94 239D AOL/Yahoo Messenger: TonyG05 HomePage: <http://www.pobox.com/~agreene/> Linux. The choice of a GNU generation <http://www.linux.org/> -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: Anthony E. Greene <mailto:agreene@;pobox.com> 0x6C94239D iD8DBQE9x9eCpCpg3WyUI50RAlRZAKDcUffwPdk3ck20gh0PkECvCz0gOgCdH4ND 7G8eFzS5OFq6IAbe0jYaLVM= =3Vyb -----END PGP SIGNATURE----- -- redhat-list mailing list unsubscribe mailto:redhat-list-request@;redhat.com?subject=unsubscribe https://listman.redhat.com/mailman/listinfo/redhat-list