Solved

Monitoring perl scripts for failure

Posted on 2011-03-08
10
391 Views
Last Modified: 2013-12-25
Hi,
I have a perl script which runs on a different host, I have to implement a proactive monitoring of this script, so that if at anytime the script fails to run I need to capture the error msg. in a text file and email it to the admin.
I am executing the script as
`rsh $host /path/to/script/script.pl argument1 argument2`

I already have the email script which takes arguments and sends out the email.
Appreciate if someone can point me in the right direction on how to capture the errors when the script fails.


Thanks
0
Comment
Question by:Mohit_t
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 84 total points
ID: 35072171

/path/to/script/script.pl argument1 argument2  2>&1 > file

Open in new window

0
 
LVL 31

Expert Comment

by:farzanj
ID: 35072380
Once this is done, you can capture the output of this file and email it
/path/to/script/script.pl argument1 argument2  2>&1 > file ; mutt -a file email@address.com

Open in new window

0
 
LVL 26

Assisted Solution

by:wilcoxon
wilcoxon earned 83 total points
ID: 35072679
farzanj's answer will work but will send you an email every time the script exits.

I would have a shell script that does something like the code attached and then call the shell script rather than the perl script via rsh.

`rsh $host /path/to/script/script.sh argument1 argument2`
#!/bin/bash
# only capture errors
/path/to/script/script.pl $1 $2 2> file
# only send the email if there was an error
if [ -s file ] mailx -s 'script.pl error' email@address.com < file

Open in new window

0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 12

Assisted Solution

by:tel2
tel2 earned 83 total points
ID: 35073199
Well said wilcocon, but when you wrote:
    if [ -s file ] mailx -s 'script.pl error' email@address.com < file
Have you tested that?  Doesn't work for me.

Didn't you mean this kind of thing:
    if [ -s file ]; then mailx -s 'script.pl error' email@address.com < file;fi
or:
    [[ -s file ]] && mailx -s 'script.pl error' email@address.com < file
?
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35073443
Nope - I didn't test it (and should have noted that).  You're probably right about the syntax - I don't write shell scripts too often and often get syntax confused between the shells (as I've been places that require csh, others that require ksh, and some that don't care).

Your first suggestion is the closest to what I wanted.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35073585
I'm a little confused about your requirements.  If you can clarify, I can give u exactly what you need.  What email program are you using?  Other conditions
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 35075910
Please clarify if you need to trap if the scripts fails to execute (compilation failure) or if you need to trap when it encounters a fatal error during runtime.

If you need to capture/trap compilation failures, then wrapping it in a shell script might be the best approach.

If you need to catch  runtime issues, then I'd handle those directly in the Perl script, possibly via a custom $SIG{__DIE__} handler or use one of the exception handling modules on cpan.
0
 

Author Comment

by:Mohit_t
ID: 35079310
Hi FishMonger,
I want to capture the runtime fatal error not the compilation errors.


Thanks
Mohit
0
 
LVL 12

Expert Comment

by:tel2
ID: 35079353
Hi Mohit_t,

What is wrong with wilcoxon's solution (and my amendment to it)?
Have you tried it?
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 35082358
The issue I see with the shell script wrapper is that it will not only send an email for fatal errors, but also for non fatal warnings since they also output on STDERR.  The OP specifically stated fatal errors.

http://perldoc.perl.org/perlfaq8.html#How-can-I-do-an-atexit%28%29-or-setjmp%28%29/longjmp%28%29?-%28Exception-handling%29

http://www.google.com/search?hl=en&client=firefox-a&hs=hce&rls=org.mozilla%3Aen-US%3Aofficial&q=perl+exception+handling&aq=f&aqi=g3g-v7&aql=&oq=
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question