More complex, yet also more robust (in my opinion) is to use Log::Log4perl along with Log::Dispatch::Email::MailSender, which does the trick well in my production code. Here's an example of how it captures the die for logging; you'd configure for emailing elsewhere, and the docs explain how:
$SIG{__DIE__} = sub { $Log::Log4perl::caller_depth++; my $logger = get_logger("YOUR_LOGGER_HERE"); $logger->fatal(@_); die @_; # Now terminate really };
This code is originally from the Log::Log4perl FAQ. The nice thing about using a logger, is that you can have it track "state"; sometimes simply having the dying error message isn't enough to track down an issue.
slight edit for clarification of email portion.----Asim, known to some as Woodrow.
In reply to Re: Have script send email if it dies
by Asim
in thread Have script send email if it dies
by bennymack
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |