#!/opt/bin/perl # ######################################################################### # # # Program to send excerpt of logfile to concerned users # # # ######################################################################### # # # Version 1.2 - Written 15.11.95 by Steffen Beyer # # # ######################################################################### # # # Copyright (C) 1995 by software design & management GmbH & Co. KG # # # ######################################################################### # # User configurable constants: # ######################################################################### # $rootdir = '/u/www/.www'; # $application = 'traverse_html'; # $logfile = "$rootdir/$application.log"; # $recipient = 'www'; # $expedient = 'webmaster'; # $subject = 'hyperlinks->nirvana in your WWW-page'; # ######################################################################### # # Some internal variables: # $version = 'version 1.2'; # $self = $0; $self =~ s!^.*/!!; # $exclfile = "$0.exclude"; # $tempfile = "/tmp/$self.temp.$$"; # $mailfile = "/tmp/$self.mail.$$"; # # Slurp exclude file into hash: # unless (open(EXCLUDE, "<$exclfile")) { die "$self: can't read '$exclfile': $!\n"; } # while () { chop; s/^\s*//; s/\s*$//; $exclude{$_} = 1; } # close(EXCLUDE); # # Open logfile: # unless (open(LOGFILE, "<$logfile")) { die "$self: can't read '$logfile': $!\n"; } # $open = 0; $send = 0; undef %copies; $user = $recipient; # while () { if (/^-+$/) { &sendfile; unless (open(TEMPFILE, ">$tempfile")) { die "$self: can't write '$tempfile': $!\n"; } $open = 1; $send = 0; undef %copies; $user = $recipient; } elsif (/^visiting/) { m!^visiting\s+'([^']+)'!; $page = $1; if ($page =~ m!^/u/([^/]+)/.www!) { $user = $1; } if ($open) { print TEMPFILE; } } elsif (/^can't find/) { $send = 1; if (m!^can't find.+/u/([^/]+)/.www!) { $copies{$1} = 1; } if ($open) { print TEMPFILE; } } elsif (/^\(coming from/) { if ($open) { print TEMPFILE; } } else { } } # close(LOGFILE); # # Send mail if one is still open: # &sendfile; # # Done: # exit; # # Subroutine that sends the mail: # sub sendfile { if ($open) { close(TEMPFILE); if (($send) && (! $exclude{$page})) { unless (open(MAILFILE, ">$mailfile")) { die "$self: can't write '$mailfile': $!\n"; } print MAILFILE "From: $expedient@sdm.de\n"; print MAILFILE "To: $user@sdm.de\n"; if ($copies{$user}) { delete $copies{$user}; } if (%copies) { print MAILFILE "Cc: ", join(',',keys(%copies)), "\n"; } print MAILFILE "Subject: $subject\n"; print MAILFILE "\n"; unless (open(TEMPFILE, "<$tempfile")) { die "$self: can't read '$tempfile': $!\n"; } while () { print MAILFILE; } close(TEMPFILE); print MAILFILE <<"EOF"; -- mailto:$expedient@sdm.de |s |d &|m | software design & management GmbH & Co. KG | | | | Thomas-Dehler-Str. 27 | | | | 81737 Munich, Germany. EOF close(MAILFILE); # if ((system("/bin/cat $mailfile") >> 8) != 0) if ((system("/bin/cat $mailfile | /opt/bin/sendmail -t") >> 8) != 0) { warn "$self: error in mail to '$user'!\n"; } if (unlink($mailfile) != 1) { die "$self: can't delete '$mailfile'!\n"; } } if (unlink($tempfile) != 1) { die "$self: can't delete '$tempfile'!\n"; } } $open = 0; $send = 0; } # # END: # __END__