in reply to Net::SSH2::Channel question

drfunk2548-

Unless I'm missing something here, I think you simply want to use Net::SSH::Perl.
The example in the docs does a great job of what you're asking:

use Net::SSH::Perl; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
Hope that helps.

-Craig

Replies are listed 'Best First'.
Re^2: Net::SSH2::Channel question
by drfunk2458 (Initiate) on Nov 07, 2007 at 16:14 UTC
    I agree that this would be a simple solution. However, maybe I am missing something b/c when I run the simple example the code hangs <forever> ... see below

    bash$ ./test-ssh.pl
    MYWIN: Reading configuration data /.ssh/config
    MYWIN: Reading configuration data /etc/ssh_config
    MYWIN: Connecting to {host}, port 22.
    MYWIN: Remote protocol version 2.0, remote software version OpenSSH_3.9p1
    MYWIN: Net::SSH::Perl Version 1.28, protocol version 2.0.
    MYWIN: No compat match: OpenSSH_3.9p1.
    MYWIN: Connection established.
    MYWIN: Sent key-exchange init (KEXINIT), wait response.
    MYWIN: Algorithms, c->s: 3des-cbc hmac-sha1 none
    MYWIN: Algorithms, s->c: 3des-cbc hmac-sha1 none
    MYWIN: Entering Diffie-Hellman Group 1 key exchange.
    MYWIN: Sent DH public key, waiting for reply.
    MYWIN: Received host key, type 'ssh-dss'.
    MYWIN: Host 'xx.xx.xx.xx' is known and matches the host key.
    MYWIN: Computing shared secret key.
    MYWIN: Verifying server signature.
    MYWIN: Waiting for NEWKEYS message.
    MYWIN: Enabling incoming encryption/MAC/compression.
    MYWIN: Send NEWKEYS, enable outgoing encryption/MAC/compression.
    MYWIN: Sending request for user-authentication service.
    MYWIN: Service accepted: ssh-userauth.
    MYWIN: Trying empty user-authentication request.
    MYWIN: Authentication methods that can continue: publickey,password,keyboard-interactive.
    MYWIN: Next method to try is publickey.
    MYWIN: Next method to try is password.
    MYWIN: Trying password authentication.
    MYWIN: Login completed, opening dummy shell channel.
    MYWIN: channel 0: new client-session
    MYWIN: Requesting channel_open for channel 0.
    MYWIN: channel 0: open confirm rwindow 0 rmax 32768
    MYWIN: Got channel open confirmation, requesting shell.
    MYWIN: Requesting service shell on channel 0.
    MYWIN: channel 1: new client-session
    MYWIN: Requesting channel_open for channel 1.
    MYWIN: Entering interactive session.
    MYWIN: Sending command: /usr/WebSphere/CommerceServer/bin/dataload/data/../test1.sh
    MYWIN: Requesting service exec on channel 1.
    MYWIN: channel 1: open confirm rwindow 0 rmax 32768

      Can you try running a simple command like /usr/bin/date and see how and what it returns?

      I'm guessing that your shell script isn't working because of environment differences. Remember, when you remotely run a command via ssh, you don't get the same environment as you get after logging in normally.

      One thing I like to do is remotely run the set command under ksh. This will dump the environment of your remote commands so you can see what you have v.s. what you need.

      -Craig