Perl Openssh



  1. Perl Openssh Cisco
  2. Perl Openssh
  3. Perl Openssh Scp_get

Perl SSH client package implemented on top of OpenSSH INSTALL ppm install Net-OpenSSH How to install Net-OpenSSH. Download and install ActivePerl; Open Command Prompt; Type ppm install Net-OpenSSH Perl 5.8 Perl 5.10 Perl 5.12 Perl 5.14 Perl 5.16 Perl 5.18 Perl 5.20 Perl 5.22 Perl 5.24. EPEL aarch64 Official perl-Net-OpenSSH-0.80-1.el8.noarch.rpm: Perl SSH client package implemented on top of OpenSSH: EPEL x8664 Official perl-Net-OpenSSH-0.80-1.el8.noarch.rpm. Perl SSH client package implemented on top of OpenSSH. To install Net::OpenSSH::ShellQuoter::fish, copy and paste the appropriate command in to your terminal.

Openssh

mlebel has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have been having problems with NET::SSH::Expect lately and I have always found it generally slow and buggy.

Upon doing some research, I found Net::OpenSSH. It appears to be working really fast and be reliable.

The only thing though is that I am having a problem running multiple commands within the same session(logging onto the device only once and run all the commands). Unless I mis-understood the documentation provided by Salvador FandiƱo, I have the following code which log's on (into a Cisco router by the way) and displays the login banner and then returns to my linux prompt.

Openssh

I hope there is a good solution. I really want to move away from Net::SSH::Expect...

Perl Openssh Cisco

  • Comment on Net::OpenSSH multiple commands
  • Download Code
Replies are listed 'Best First'.
Re: Net::OpenSSH multiple commands
by salva (Canon) on Apr 19, 2012 at 21:06 UTC
    Ideally, you should be able to run commands sequentially:

    Unfortunately, some devices do not support this mode of operation and force you to talk to some kind of custom shell.

    In that case, in order to start a remote shell from Net::OpenSSH, call open2pty without passing any command:

    ...and then, use Expect to talk to the shell.

    Sometimes the following approach also works:

    See also the FAQ section from the module docs.

[reply]
[d/l]
[select]
Re: Net::OpenSSH multiple commands
by zentara (Archbishop) on Apr 19, 2012 at 19:27 UTC
    I hope there is a good solution. I really want to move away from Net::SSH::Expect...

    It's not Net::OpenSSH, but Net::SSH2 can do multiple commands thru it's channel's shell() method. Try it, if you can't find a Net::OpenSSH solution. Keys Auth logins is also supported.

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
[reply]
[d/l]
Re: Net::OpenSSH multiple commands
by mlebel (Hermit) on Apr 20, 2012 at 19:21 UTC

    Thank you zentara and salva for your answers.

    Unfortunately, after messing with this all day, I wasn't able to get anything working from either one your posts. My thought now is to post the Net::SSH:Expect code that I've been using and I am trying to convert to Net::OpenSSH. Maybe this will help identify what I am trying to achieve, and the reasons behind it. So, here it is...

    Note that this code is using a username and password. If possible, I would rather use public key authentication.

    Is this possible using the Net::OpenSSH Module (with maybe expect)? If so, how could I write it?

    Thanks

[reply]
[d/l]
Re: Net::OpenSSH multiple commands
by mlebel (Hermit) on Apr 23, 2012 at 17:09 UTC

    After a few more days of messing with this, I have gotten the following code to work.

    This code, however, gives me 2 errors...

    I have tried searching for a fix for them but I haven't found anything.

    Would anyone know how I can fix these errors?

[reply]
[d/l]
[select]
    Re^2: Net::OpenSSH multiple commands
    by salva (Canon) on Apr 24, 2012 at 09:31 UTC
    The line ... ... does mostly nothing, delete it.
    This code, however, gives me 2 errors

    Those are probably harmless, generated by OpenSSH because you are requesting a remote pty but attaching it to a non-pty stream.

    BTW, when writing follow ups to previous comments, do not reply to main question but to those, otherwise the person you are responding (i.e. me) will probably miss the reply.

[reply]
[d/l]
    Re^3: Net::OpenSSH multiple commands
    by mlebel (Hermit) on Apr 24, 2012 at 11:32 UTC

    I removed the line:(for which I just realized that I had forgot to change 'show ip arp')

    and the results were that the 'channel 4: open failed: resource shortage:' error went away. As for the remaining error, I guess i'll just filter it out since it's probably harmless as you said.

    I appreciate the tip on writing follow ups, I never realized that it could cause that. Now I have a much more solid solution compared to using the Net::SSH::Expect module. For those interested, I cleaned up my code:...

    Thank you Salva

[reply]
[d/l]
[select]
    Re^3: Net::OpenSSH multiple commands
    by mlebel (Hermit) on Apr 24, 2012 at 19:10 UTC

    Hi Salva, I believe you are probably the best person to answer this:... I changed the line:

    to this:

    and I get an error (I think might be caused by openssh) that says 'Bad packet length 688328622.' (The length numbers change every time I run the code). If i remove some parts of the commands such as 'terminal length 0' and run it again, the error goes away. The same goes if I leave 'terminal length 0' in there and replace say 'show ip accounting' by 'show ip route'.(no error)

    So it seems that a combination of commands will trigger this error. I do have to say though that the output is ok regardless of the error. Would this be another error which I should Ignore? or could this be a bug?

    Thanks

[reply]
[d/l]
[select]
    Re^4: Net::OpenSSH multiple commands
    by salva (Canon) on Apr 25, 2012 at 09:22 UTC
    Re^5: Net::OpenSSH multiple commands
    by mlebel (Hermit) on Apr 25, 2012 at 11:36 UTC
    Some notes below your chosen depth have not been shown here
Re: Net::OpenSSH multiple commands
by mlebel (Hermit) on May 24, 2012 at 15:27 UTC

    The solution that ended up working for me was to go back to using Net::SSH::Expect and remove the username/password login and make it use public-key authentication. So far (knock on wood) this seems to work..it's no longer slow and it seems to login everytime..I can also run multiple commands and get the results expected.. Here is a sample of code I used to make this work. (taken from it's documentation)

    I hope this helps someone.

    Also, if there is a way to do it using the Net::OpenSSH module, a sample code would be appreciated. Otherwise, enjoy this working solution

    Marc

[reply]
[d/l]
Re: Net::OpenSSH multiple commands
by Anonymous Monk on Apr 07, 2013 at 19:04 UTC
    I don't know who this might help, but here is a simple way to join multiple commands and run them at once on a remote server. It just connects to the server, finds the directory you want, and prints its total contents. --Ben.
[reply]
[d/l]
    Re^2: Net::OpenSSH multiple commands
    by salva (Canon) on Apr 07, 2013 at 20:06 UTC
    It is recommendable to let Net::OpenSSH quote the command arguments. Double references can be used to let some fragment pass unquoted: Otherwise, in case $path_to_file contained shell metacharacters it could produce undesired results or even be a security hole.

    Note that currently, argument quoting expect some derivative of the Bourne shell on the remote side. Support for quoting arguments for other shells is in the works though.

[reply]
[d/l]
[select]

Perl Openssh

Perl

Perl Openssh Scp_get





Comments are closed.