Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not find a way to prevent Net::SSH::Perl from exiting the script if the detination port has no service. #20

Closed
medeiros1 opened this issue Jul 13, 2022 · 5 comments

Comments

@medeiros1
Copy link

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

@sensei-hacker
Copy link

sensei-hacker commented Jul 13, 2022

You can do:

my $ssh;
eval { $ssh = Net::SSH::Perl->new($ConfigP::remotehost,options => ["Port $remoteport"]) };
warn $@ if $@;



@medeiros1
Copy link
Author

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.

@rwp0
Copy link

rwp0 commented Jul 16, 2022

I think the newer try/catch syntax can be used here in place of eval as well.

@briandfoy
Copy link
Contributor

briandfoy commented Jul 26, 2023

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.

@medeiros1
Copy link
Author

Thanks, the eval method worked for me as desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants