[EMAIL PROTECTED] wrote:
MNibble
<[EMAIL PROTECTED]
de> To
beginners@perl.org
07/19/2005 09:54 cc
AM
Subject
Re: catching signal for an email
notification
[EMAIL PROTECTED] wrote:
Perl'ers
I my code I wrote a routine that executes return code signals. My point
being is if after any particular line of code make a call to check its
success or failure.
My question is if after any code system call or non system call failure
according to
$? == -1
? & 127 or
$? >> 8
can I send an email with that return code in as the message and or
subject?
I f so how and what would the code look like?
thank you,
derek
Please see lines 70-84 and 124
(See attached file: test.pl)
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
I', not totaly sure about you if elsif elsif ...
waht about
if ( it breaks )
{
$content ="more on $?";
mailme($content,$?);
}
sub mailme
{
my $stuff = "Command die with ",shift;
my $content = "lots of text an stuff PLUS more on",shift;
open(MAIL , "| /usr/sbin/sendmail -t") or die $!;
my $msg = new MIME::Lite ;
my $tomail="[EMAIL PROTECTED]" ;
$msg = build MIME::Lite
From => 'your server' ,
To => $tomail ,
Subject => "$stuff" ,
Type => 'TEXT',
Data => "$content";
attach $msg
Type => "text" ,
Path => "/test.csv" ,
Encoding => "base64",
Filename => "$file.csv" ;
$msg->print(\*MAIL) ;
close(MAIL) ;
}
-------------the if it breaks part ----------
my $status = $?;
my $error=$status & 0x00FF;
my $exam =$status & 0xFF00;
if ($error != 0)
{
print "exit value $?\n";
my $ex1 = ($exam & 127);
print "show Signal $ex1 \n";
my $ex2 = ($exam & 128);
print "Coredump $ex2 \n";
}
----------------------------------------------
with regards
MNibble
I was sort of confused when you said if it breaks... what breaks my signal
routine?
So is the code correct when I say &mailme($!); ????
sub signal
{
if ($? == -1) {
print "failed to execute: $!\n";
&mailme($!);
}
elsif ($? & 127) {
printf "child dies with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with core' :
'without core';
&mailme($!);
}
elsif ( $? >> 8) {
printf "child exited with value %d\n", $? >> 8;
&mailme($!);
}
}
and what exactly is the "-------------the if it breaks part ----------"
section?
Will you explain this? Whats with these hex numbers and why? Don be
offended just trying to be clear!
Is there anymore error checking I can do to improve its functionality?
thank you,
derek
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
Sorry for my bad english und coding style ... so i try again.
If it breaks ... just met the execution of the command that you try to
check on.
i think your routine will work, but i was/am somehow confused about your
if
elsif
elsif
statment, it will work ... but i found it a bit .. strange this the
elsif parts can only happen if the if part hasn't already happend. And
since on an error it will return -1, so you never reach the elsif part
for more examination of the return code.
The bitmasking was just for the extraction of the values from the $?
variable. I think you don't have to do it, but it should illustrate the
the status var is a 16Bit var and the upper 8 bit are the return value
while the lower 8 bit give you a hint what is really going on.
After all i'm only human i have made mistakes in the past and i will do
some in the furture.
with regards
MNibble
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>