Closed medeiros1 closed 1 year ago
You can do:
my $ssh;
eval { $ssh = Net::SSH::Perl->new($ConfigP::remotehost,options => ["Port $remoteport"]) };
warn $@ if $@;
Thanks for the trick ! I didn't realize that eval can be used to prevent a script from exiting when a routine exits. After you wrote it, it became clear to me that it works.
I think the newer try
/catch
syntax can be used here in place of eval
as well.
I've forked this project at briandfoy/net-ssh-perl, and you can reopen this issue there if you'd like. Otherwise, I'll add it myself at some later time. See #22.
If you include text like transferred from linkley/Net-SSH-Perl#20
, GitHub should make a reference between the two issues.
But, I think this issue has been resolved and you can close it.
Thanks, the eval method worked for me as desired.
Hi, thanks for this well working module, it does a great job. Unfortunately I could not find a way to prevent the script exiting when the destination port is not under service: If the port is reachable all works fine.
my $remoteport="3302"; my $ssh = Net::SSH::Perl->new($ConfigP::remotehost,options => ["Port $remoteport"]); ^^^^^^^^ exits after the line above, if the port does not provide a service ^^^^^^^^ $ssh->login($ConfigP::remoteuser,$ConfigP::remotepass); my($stdout, $stderr, $exit) = $ssh->cmd("")
Is there a method in the module to check for a port under service instead of exiting ?
Regards Rolf