Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

net::ssh::Perl connecting to f-secure ssh server

by tweetiepooh (Hermit)
on Oct 05, 2007 at 16:18 UTC ( [id://642950]=perlquestion: print w/replies, xml ) Need Help??

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

Hi monks

We need to write a script that will connect to a softswitch (telco), run commands retrieving output to files and sometimes using some of that output as parameters to more commands.

The softswitch runs on Windows NT server and uses F-Secure 3.2.0. The client box will be Solaris with Perl 5.8.8.

I can run ssh from the shell and connect OK. I can run the commands and see output on screen.

I have started to write a demo in Perl and I can login fine, using ssh->shell() I can see the post login welcome and the "shell" promp (oddchar + <). If I go interactive I can see my input on the screen but no response from server. If I send commands I get an error.

#!/usr/local/bin/perl -w use strict; use Net::SSH::Perl; my $ssh = Net::SSH::Perl->new("host",(protocol=>'2',port=>'52000',debu +g=>'true')); $ssh->login("user","pass"); $ssh->cmd("exit");
Gives lots of debug info showing attempt to use key files etc all fail (OK) then using password. I get a login completed.
prospero: Next method to try is password. prospero: Trying password authentication. prospero: Login completed, opening dummy shell channel. prospero: channel 0: new [client-session] prospero: Requesting channel_open for channel 0. prospero: channel 0: open confirm rwindow 100000 rmax 16384 prospero: Got channel open confirmation, requesting shell. prospero: Requesting service shell on channel 0. prospero: channel 1: new [client-session] prospero: Requesting channel_open for channel 1. prospero: Entering interactive session. prospero: Sending command: exit prospero: Requesting service exec on channel 1. prospero: channel 1: open confirm rwindow 100000 rmax 16384
Then it waits. If I press ENTER
Received disconnect message: Window overflow received channel data. at /usr/local/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/SSH2.pm line 284
Ideas much appreciated.

I don't need a great deal of fancy stuff. The commands and output are pretty fixed, no real nasties like running passwd.

Replies are listed 'Best First'.
Re: net::ssh::Perl connecting to f-secure ssh server
by liverpole (Monsignor) on Oct 05, 2007 at 23:27 UTC
    Hi tweetiepooh,

    This may or may not have something to do with your problem.

    The other day, my boss asked me to research a problem he was seeing with Net::SSH::Perl.  He was trying to connect to a remote system, and having to wait for almost a minute before the connection would succeed.  What he then asked me was:  "Can you and Perlmonks help me research this problem?", which I got an immense kick out of. :-)

    I did a search, and found that Net::SSH::Perl can take a long time if Math::BigInt::GMP isn't installed.  Once we installed it, the login time was respectably diminished.

    As I said, I haven't any idea if that is related to your problem in any way, but it's certainly something to try.  And if your problem turns out to be something else, keep in mind that without installing Math::BigInt::GMP may cause you to experience a marked decrease in connection latency.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
      Believe me I know about all those wierd maths libraries and have got them all. It took ages to build pari for Math::Pari for Crypt::RSA etc but I did get them. Login speed is fine so not an issue, thanks for offering the idea though, getting Net::SSH::Perl installed on Solaris 8 is a real pain.
Re: net::ssh::Perl connecting to f-secure ssh server
by cmv (Chaplain) on Oct 05, 2007 at 17:48 UTC
    What do you get if you change your code to something like this:
    #!/usr/local/bin/perl -w use strict; use Net::SSH::Perl; my $ssh = Net::SSH::Perl->new("host",(protocol=>'2',port=>'52000',debu +g=>'true')); $ssh->login("user","pass"); my ($stdout, $stderr, $exit) = $ssh->cmd("date /t"); print "exit=$exit\nstdout=$stdout\nstderr=$stderr\n";
      Date is not a valid command. It's not really a "computer", then commands are things like 'lssub:sn=all;' followed by some text out.

      If I use $ssh->shell; I do see the login prompt but can't get anything further.

Re: net::ssh::Perl connecting to f-secure ssh server
by mr_mischief (Monsignor) on Oct 05, 2007 at 16:28 UTC
    My questions aren't Perl-specific, but ssh-specific. re you sure your F-Secure ssh server and your command-line ssh are using sshv2? What happens if you set protocol to '2,1' or '1,2' or maybe just '1'?
      It definitely use version 2. I know I trimmed that bit out but I did try. Version 1 won't even connect.
        I think I misread your code and sample output anyway. You are getting connected, but the connection isn't doing what you want? Is that closer to what's happening?

        A quick note regarding Net::SSH::Perl and myself: I'm no expert on this project, and I won't claim to be. I'm hoping if you haven't stumbled over some solution on your own that more feet will stumble faster. :-)

        What happens if you use a command other than 'exit'? My first guess is that you're not getting the command you think you are. An explanation of that thought will be below, but checking the return values on functions (especially those involving more than one machine) should probably be a habit. My guess after that, I think, would be that the exit command on your remote end doesn't close the connection, which you'd have to do manually. Does the connection get closed when you issue the exit command when ssh'ed in directly?

        I'm not sure if you've tried it already, but there's Net::SSH, Net::SFTP, and Net::SSH::Perl mailing list that's archived at the modules' Sourceforge project. There's a good chance someone there might have had similar issues. Please let us know if you find something there that helps.

        I notice you're not checking the return value on the cmd() method. According to a message on the afore-mentioned archive, at least one person thinks shell builtins don't work with cmd(). I'd guess the exit command wouldn't be a separate executable. Over on CPAN::Forum this message alludes to needing use_pty enforced on cmd() as well as shell() in order to use a shell on the remote end non-interactively. Net::SSH::Perl::SSH2 appears not to do this, and in fact a quick check of Net::SSH::Perl would seem to confirm it.

        Given the above information, I'd try using the shell() method and typing 'exit' as a command interactively just to make sure it works there. If that works and I really needed to make it work from the cmd() method, I'd figure out what it so different between shell() and cmd(). Then perhaps I'd subclass Net::SSH::Perl::SSH2 to make cmd() a little more like shell(), or send a patch to the maintainers that enables such use.

Re: net::ssh::Perl connecting to f-secure ssh server
by tweetiepooh (Hermit) on Oct 12, 2007 at 21:30 UTC
    We dun it!!!

    Eventually using Net::SSH::Expect we got the tip in that modules docs that got it working. Not tried it with the other modules used yet but at least I now have comms.

    The solution?? We remember I said we are talking to an application on a Windoze box? Net::SSH::Expect has a command/method called terminator used to change the command terminator from the nice normal '\n' to '\n\r'. Did this and presto, we get responces.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://642950]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found