Re: eval on a $SIG{KILL}- newbie question
I think Bob's theory 1 fits. The die is never called. You put an alarm handler into your program which is set for 10 seconds. I suppose the timeout for the ssh module is more like 30 seconds, so the alarm catches first. On Tue, Aug 27, 2002 at 01:46:20PM -0400, Chad Kellerman wrote: How do I catch the die() in an eval statement; I have been using: eval { alarm 10; $ssh-login($user); ($out, $error, $exit) = $ssh-cmd($cmd); alarm(0); }; # end of eval statement if ($@ =~ /Can't/) { try_again($ip, $host_name) = @_; } Since you didn't install your own signal handler for ALRM the standard handler emits a Alarm clock which you most likely find in $@. Try printing $@ instead of matching it, and you'll see what happened. -- Well, then let's give that Java-Wussie a beating... (me) Michael Lamertz| +49 2234 204947 / +49 171 6900 310 Sandstr. 122 | [EMAIL PROTECTED] 50226 Frechen | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
eval on a $SIG{KILL}- newbie question
Hello, I am writing a script on a linux server use Net::SSH::Perl. Every once in a while the ssh connection to a remote server dies or it just can't connect. the perl module send a $SIG{KILL} to the script when ever this happens. Which isn't what I want. I am trying to put the kill in an eval stattement and have it wait a few minutes before it tries to connect again. But I am never getting past the eval statement. Here's my code: eval { local $SIG{KILL} = sub {die died }; alarm 10; $ssh-login($user); ($out, $error, $exit) = $ssh-cmd($cmd); alarm(0); }; # end of eval statement if ($@ =~ /died/) { try_again($host_ip, $host_name, $group_dir) = @_; } It the try_again sub I have it email me (which works) but I have it print that it's entering the failed subroutine but it never does that. Does anyone see what I am doing wrong? Thanks again for all the help. --chad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: eval on a $SIG{KILL}- newbie question
-Original Message- From: Chad Kellerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 27, 2002 8:33 AM To: [EMAIL PROTECTED] Subject: eval on a $SIG{KILL}- newbie question Hello, I am writing a script on a linux server use Net::SSH::Perl. Every once in a while the ssh connection to a remote server dies or it just can't connect. the perl module send a $SIG{KILL} to the script when ever this happens. Which isn't what I want. I am trying to put the kill in an eval stattement and have it wait a few minutes before it tries to connect again. But I am never getting past the eval statement. Here's my code: eval { local $SIG{KILL} = sub {die died }; alarm 10; $ssh-login($user); ($out, $error, $exit) = $ssh-cmd($cmd); alarm(0); }; # end of eval statement if ($@ =~ /died/) { try_again($host_ip, $host_name, $group_dir) = @_; } It the try_again sub I have it email me (which works) but I have it print that it's entering the failed subroutine but it never does that. Does anyone see what I am doing wrong? Thanks again for all the help. Are you saying Net::SSH::Perl sends SIGKILL to the calling script? You can't catch SIGKILL. If you're trying to catch the 10 second timeout, use $SIG{ALRM}. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: eval on a $SIG{KILL}- newbie question
Bob, Thanks for the responce. I did not realize you can't trap a $SIG{kill}. I guess the only way around this is to change the perl module. Change it so it doesn't die but return a value and grab that value in the eval statement? thanks again, --chad On Tue, 27 Aug 2002 08:41:31 -0400 Bob Showalter [EMAIL PROTECTED] wrote: -Original Message- From: Chad Kellerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 27, 2002 8:33 AM To: [EMAIL PROTECTED] Subject: eval on a $SIG{KILL}- newbie question Hello, I am writing a script on a linux server use Net::SSH::Perl. Every once in a while the ssh connection to a remote server dies or it just can't connect. the perl module send a $SIG{KILL} to the script when ever this happens. Which isn't what I want. I am trying to put the kill in an eval stattement and have it wait a few minutes before it tries to connect again. But I am never getting past the eval statement. Here's my code: eval { local $SIG{KILL} = sub {die died }; alarm 10; $ssh-login($user); ($out, $error, $exit) = $ssh-cmd($cmd); alarm(0); }; # end of eval statement if ($@ =~ /died/) { try_again($host_ip, $host_name, $group_dir) = @_; } It the try_again sub I have it email me (which works) but I have it print that it's entering the failed subroutine but it never does that. Does anyone see what I am doing wrong? Thanks again for all the help. Are you saying Net::SSH::Perl sends SIGKILL to the calling script? You can't catch SIGKILL. If you're trying to catch the 10 second timeout, use $SIG{ALRM}. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: eval on a $SIG{KILL}- newbie question
-Original Message- From: Chad Kellerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 27, 2002 8:58 AM To: [EMAIL PROTECTED] Subject: Re: eval on a $SIG{KILL}- newbie question Bob, Thanks for the responce. I did not realize you can't trap a $SIG{kill}. I guess the only way around this is to change the perl module. Change it so it doesn't die but return a value and grab that value in the eval statement? Wait a minute. die() is vastly different from sending SIGKILL. If the module simply die()'s, you catch that by examining $@ after the eval block. thanks again, --chad On Tue, 27 Aug 2002 08:41:31 -0400 Bob Showalter [EMAIL PROTECTED] wrote: -Original Message- From: Chad Kellerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 27, 2002 8:33 AM To: [EMAIL PROTECTED] Subject: eval on a $SIG{KILL}- newbie question Hello, I am writing a script on a linux server use Net::SSH::Perl. Every once in a while the ssh connection to a remote server dies or it just can't connect. the perl module send a $SIG{KILL} to the script when ever this happens. Which isn't what I want. I am trying to put the kill in an eval stattement and have it wait a few minutes before it tries to connect again. But I am never getting past the eval statement. Here's my code: eval { local $SIG{KILL} = sub {die died }; alarm 10; $ssh-login($user); ($out, $error, $exit) = $ssh-cmd($cmd); alarm(0); }; # end of eval statement if ($@ =~ /died/) { try_again($host_ip, $host_name, $group_dir) = @_; } It the try_again sub I have it email me (which works) but I have it print that it's entering the failed subroutine but it never does that. Does anyone see what I am doing wrong? Thanks again for all the help. Are you saying Net::SSH::Perl sends SIGKILL to the calling script? You can't catch SIGKILL. If you're trying to catch the 10 second timeout, use $SIG{ALRM}. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: eval on a $SIG{KILL}- newbie question
Sorry everybody, I have been trying to work on this all day but nothing... IF a perl module uses: connect($sock, sockaddr_in($rport, $raddr)) or die Can't connect to $ssh-{host}, port $rport: $!; How do I catch the die() in an eval statement; I have been using: eval { alarm 10; $ssh-login($user); ($out, $error, $exit) = $ssh-cmd($cmd); alarm(0); }; # end of eval statement if ($@ =~ /Can't/) { try_again($ip, $host_name) = @_; } but the eval still doesn't pass the program to the sub try_again. Sorry for being such a newbie, but I have been trying to follow the oreilly book and still it just isn't happening. thanks, chad On Tue, 27 Aug 2002 09:28:52 -0400 Bob Showalter [EMAIL PROTECTED] wrote: -Original Message- From: Chad Kellerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 27, 2002 8:58 AM To: [EMAIL PROTECTED] Subject: Re: eval on a $SIG{KILL}- newbie question Bob, Thanks for the responce. I did not realize you can't trap a $SIG{kill}. I guess the only way around this is to change the perl module. Change it so it doesn't die but return a value and grab that value in the eval statement? Wait a minute. die() is vastly different from sending SIGKILL. If the module simply die()'s, you catch that by examining $@ after the eval block. thanks again, --chad On Tue, 27 Aug 2002 08:41:31 -0400 Bob Showalter [EMAIL PROTECTED] wrote: -Original Message- From: Chad Kellerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 27, 2002 8:33 AM To: [EMAIL PROTECTED] Subject: eval on a $SIG{KILL}- newbie question Hello, I am writing a script on a linux server use Net::SSH::Perl. Every once in a while the ssh connection to a remote server dies or it just can't connect. the perl module send a $SIG{KILL} to the script when ever this happens. Which isn't what I want. I am trying to put the kill in an eval stattement and have it wait a few minutes before it tries to connect again. But I am never getting past the eval statement. Here's my code: eval { local $SIG{KILL} = sub {die died }; alarm 10; $ssh-login($user); ($out, $error, $exit) = $ssh-cmd($cmd); alarm(0); }; # end of eval statement if ($@ =~ /died/) { try_again($host_ip, $host_name, $group_dir) = @_; } It the try_again sub I have it email me (which works) but I have it print that it's entering the failed subroutine but it never does that. Does anyone see what I am doing wrong? Thanks again for all the help. Are you saying Net::SSH::Perl sends SIGKILL to the calling script? You can't catch SIGKILL. If you're trying to catch the 10 second timeout, use $SIG{ALRM}. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: eval on a $SIG{KILL}- newbie question
-Original Message- From: Chad Kellerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 27, 2002 1:46 PM To: [EMAIL PROTECTED] Subject: Re: eval on a $SIG{KILL}- newbie question Sorry everybody, I have been trying to work on this all day but nothing... IF a perl module uses: connect($sock, sockaddr_in($rport, $raddr)) or die Can't connect to $ssh-{host}, port $rport: $!; How do I catch the die() in an eval statement; I have been using: eval { alarm 10; $ssh-login($user); ($out, $error, $exit) = $ssh-cmd($cmd); alarm(0); }; # end of eval statement if ($@ =~ /Can't/) { try_again($ip, $host_name) = @_; } but the eval still doesn't pass the program to the sub try_again. Sorry for being such a newbie, but I have been trying to follow the oreilly book and still it just isn't happening. That's how you do it. Here's a boiled-down example: eval { foo(); }; if ($@ =~ /Can't/) { print Caught it!: $@\n; } sub foo { die Can't connect\n } If I run that, it prints: Caught it!: Can't connect So, I would look for the following: 1. The code inside the eval is dying, but not with the Can't connect message. Try printing $@ after the eval to see what it contains. 2. The code in the module is catching the die() somewhere else, and not passing it back to you. 3. The die() in the module is never being called. Also, what is this supposed to be doing? It looks very odd: try_again($ip, $host_name) = @_; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: eval on a $SIG{KILL}- newbie question
Chad Kellerman wrote: Sorry everybody, I have been trying to work on this all day but nothing... IF a perl module uses: connect($sock, sockaddr_in($rport, $raddr)) or die Can't connect to $ssh-{host}, port $rport: $!; How do I catch the die() in an eval statement; I have been using: eval { alarm 10; $ssh-login($user); ($out, $error, $exit) = $ssh-cmd($cmd); alarm(0); }; # end of eval statement if ($@ =~ /Can't/) { try_again($ip, $host_name) = @_; you put your try_again() function in the left side of the '=' operator. i am not sure if that's just your typo or not. but you can only do this if your function returns a lvalue like: sub try_again: lvalue{ #-- must return a lvalue(basically, not a constant); return $var; } otherwise, it won't even compile. the following catches the die() signal: eval{ function(); }; if($@){ another_function($@); }else{ print nothing happened\n; } sub function{ die whatever; } sub another_function{ print shift; } if you don't like to use the eval{}, $@ stuff, you can set up a __DIE__ handler like: $SIG{__DIE__} = sub { }; david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]