Click here to get back home

Re: Re: problems using Net::SSH::Perl in a while loop

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Re: Re: problems using Net::SSH::Perl in a while loop Thonas Siegenthaler 04-29-2005
Get Chitika Premium
Posted by Thonas Siegenthaler on April 29, 2005, 1:45 pm
Please log in for more thread options


Hi Mark

thank you for answering. Net::SSH::Perl calls Carp::croak(), which calls
die().

The question is what does the module do, if there is no die() call.
I replaced Carp::croak() with a warn-message. The result is a endless
list of error messages.

Has anyone of you ever had a similar problem? Probably I should contact the
developer of this module. It is not very intelligent to use a die() call
within a module.
A good module returns a errorcode and does not cancel the script.

Greetz
--Thomas

Mark Clements schrieb:
>Thonas Siegenthaler wrote:
>> I want to usw Net:SSH::Perl to automatically run some commands on several
>> hosts.
>> All the hostnames are stored in a database.
>>
>> I decided to use Net::SSH::Perl because I can configure everything I
>> need.
>> The auth is
>> done by a SSH-Key (RSA). Unfortunately not all of the hosts in the DB
>> have
>> the SSH
>> Key stored in their ~/.ssh/authorized_keys. When I try to connect to one
>> of
>> these
>> hosts using SSH2, my script dies because of a Carp::croak() call in the
>> Net::SSH::Perl::AuthMgr module (line 142).
>>
>> Is there a way to turn off this "die" and just get a error-message
>> instead?
>> If a hosts doesn't
>> have this ssh-key, I don't want to abort my script, I wnat to continue
>> with
>> the next hostname
>> instead.
>
>I'm not familiar with this module, but you can normally wrap die calls
>with eval:
>
>eval {
>print "enter evaln";
>die "die here";
>print "end evaln";
>};
>if($@){
>print "trapped error - $@";
># handle error
>}
>print "script continues...n";
>
>perldoc -f eval
>
>Mark





Posted by Radomir Hejl on April 29, 2005, 10:24 pm
Please log in for more thread options



> Hi Mark
>
> thank you for answering. Net::SSH::Perl calls Carp::croak(), which calls
> die().
>
> The question is what does the module do, if there is no die() call.
> I replaced Carp::croak() with a warn-message. The result is a endless
> list of error messages.
>
> Has anyone of you ever had a similar problem? Probably I should contact
> the
> developer of this module. It is not very intelligent to use a die() call
> within a module.
> A good module returns a errorcode and does not cancel the script.
>
> Greetz
> --Thomas
>
> Mark Clements schrieb:
>>Thonas Siegenthaler wrote:
>>> I want to usw Net:SSH::Perl to automatically run some commands on
>>> several
>>> hosts.
>>> All the hostnames are stored in a database.
>>>
>>> I decided to use Net::SSH::Perl because I can configure everything I
>>> need.
>>> The auth is
>>> done by a SSH-Key (RSA). Unfortunately not all of the hosts in the DB
>>> have
>>> the SSH
>>> Key stored in their ~/.ssh/authorized_keys. When I try to connect to one
>>> of
>>> these
>>> hosts using SSH2, my script dies because of a Carp::croak() call in the
>>> Net::SSH::Perl::AuthMgr module (line 142).
>>>
>>> Is there a way to turn off this "die" and just get a error-message
>>> instead?
>>> If a hosts doesn't
>>> have this ssh-key, I don't want to abort my script, I wnat to continue
>>> with
>>> the next hostname
>>> instead.
>>
>>I'm not familiar with this module, but you can normally wrap die calls
>>with eval:
>>
>>eval {
>>print "enter evaln";
>>die "die here";
>>print "end evaln";
>>};
>>if($@){
>>print "trapped error - $@";
>># handle error
>>}
>>print "script continues...n";
>>
>>perldoc -f eval
>>
>>Mark

I use this module and also tried to circumvent dying of script.
I manually implemented all machines with the ssh keys and ping them before
running the relevant part of the script to evade unavailabity of the
machines.
Radek H.




Posted by Sisyphus on April 29, 2005, 10:26 pm
Please log in for more thread options



> Hi Mark
>
> thank you for answering. Net::SSH::Perl calls Carp::croak(), which calls
> die().
>
> The question is what does the module do, if there is no die() call.
> I replaced Carp::croak() with a warn-message. The result is a endless
> list of error messages.
>

You have amended the code in the module. I don't think that's what Mark
intended. I'll see if I can explain ....

In your perl script you are calling a Net::SSH::Perl function - and that
function sometimes dies, killing the whole script. Let's call that function
Net::SSH::Perl::return_something().

So - your script contains (in a loop):

$ret = Net::SSH::Perl::return_something();

What Mark is suggesting (I think) is that you change your *script* to
something like:

eval {$ret = Net::SSH::Perl::return_something();};
if($@) { print "return_something() died with message: $@n"}
# script keeps running

There is no need to modify the module.

(You may be quite correct in saying that these functions ought not to call
die() .... I'm not arguing about that :-)

Cheers,
Rob




Similar ThreadsPosted
problems using Net::SSH::Perl in a while loop April 29, 2005, 10:09 am
Problems with CGI::Session in Perl August 8, 2005, 11:25 am
perl SAP RFC SDK make problems in fedora December 2, 2005, 2:47 am
Problems finding gd.pm in perl 5.8.6 using linux February 16, 2006, 4:59 pm
Problems with Apache 2.0, mod_perl2 and perl May 31, 2006, 3:48 pm
Problems using GD.pm January 8, 2005, 8:05 pm
Problems when using Net::MSN 1.022 May 4, 2005, 1:20 pm
LWP problems July 11, 2005, 3:50 pm
PPM Problems on Win.XP November 5, 2007, 4:26 pm
LWP Problems (Authentication?) September 5, 2004, 7:12 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap