in reply to Problem while using Net::SSH::Perl module

Your script does not work because SSH launches a new shell for every command. You have to put all the commands in the same cmd invocation using the semicolon (;) or the and operator (&&) to join them:
my $job = $ssh->cmd(<<SHELL); source /home/venkatas/.cshrc; setenv DISPLAY linux37:0; bsub -q linux64_idc_1g xterm & SHELL
Though, this will not work either, because the cmd method would not return control until the xterm is closed, even if it is run in the background. You will have to use the non-blocking features of Net::SSH::Perl for that.

Replies are listed 'Best First'.
Re^2: Problem while using Net::SSH::Perl module
by almut (Canon) on Oct 09, 2009 at 13:30 UTC
    Though, this will not work either, because the cmd method would not return control until the xterm is closed

    I think the idea here is to submit the xterm command to the linux64_idc_1g LSF queue, so LSF will then run the command (when it gets around to it).  In other words, the bsub command should return more or less immediately.  (Also, the bsub command should "capture" the current environment (such as DISPLAY) and LSF should reinstate it when the queued command is being run. So, it could in theory work, provided the X server that DISPLAY points to allows access from the (possibly remote) LSF cluster machine...)

      oh, I see, but then, the ampersand is useless!

        That's correct, as (I think) is your observation that the individual commands would be run in separate shells by Net::SSH::Perl, so the sourced environment, etc. would not persist...

Re^2: Problem while using Net::SSH::Perl module
by venkatas (Initiate) on Oct 12, 2009 at 07:19 UTC

    Thanks for suggesting me to use SHELL in my code but I'm unable to source my .cshrc on remote host the way you mentioned.

    Can you help me in this too.

    thanks in advance.

      it works for me, so, unless you give us some more details about how it fails for you, we will be unable to help you further!
        Hi

        Its not working for me and I'm using folowing code

        #! /usr/local/bin/perl -w use strict; use Net::SSH::Perl; #my $host="192.168.10.32";## remote host IP address my $host="netli01"; ##remote hostname my $usr="venkatas"; ##user login ID my $pass="banu84"; ## user login password ###### set-up remote connection my $ssh = Net::SSH::Perl->new($host, interactive=> 0, debug=> 1, proto +col=> '2,1'); #my $ssh = Net::SSH::Perl->new($host, interactive=> 1, debug=> 1, prot +ocol=> '2,1'); ## This stderr and stdout will help to findout whether the commands ar +e executing or not $ssh->register_handler("stderr", sub { my($channel, $buffer) = @_; print "** Standard Error - I received this:\n", $buffer->byt +es; }); # This trigger works perfectly $ssh->register_handler("stdout", sub { my($channel, $buffer) = @_; print "** Standard Out - I received this:\n", $buffer->byte +s; }); ## remote login authentication $ssh->login($usr,$pass); #$ssh->login(); #my $job2 = $ssh->cmd("set_calico_C1" ); #my $job3 = $ssh->cmd("calico" ); #my $job4 = $ssh->cmd("date" ); #my $job2 = $ssh->cmd('setenv DISPLAY linux37:0'); #my $job3 = $ssh->cmd("bsub -q linux64_idc_1g xterm & " ); ## commands to be executed on remote host my $job1 = $ssh->cmd(<<SHELL); source /home/venkatas/.cshrc; setenv DISPLAY linux37:0; /usr/local/lsf7.0/7.0/linux2.6-glibc2.3-x86/bin/bsub -q linux64_idc_1g + xterm SHELL And the error I'm facing is linux37: Reading configuration data /home/venkatas/.ssh/config linux37: Reading configuration data /etc/ssh_config linux37: Connecting to netli01, port 22. linux37: Remote protocol version 1.99, remote software version OpenSSH +_3.9p1 linux37: Net::SSH::Perl Version 1.34, protocol version 2.0. linux37: No compat match: OpenSSH_3.9p1. linux37: Connection established. linux37: Sent key-exchange init (KEXINIT), wait response. linux37: Algorithms, c->s: 3des-cbc hmac-sha1 none linux37: Algorithms, s->c: 3des-cbc hmac-sha1 none linux37: Entering Diffie-Hellman Group 1 key exchange. linux37: Sent DH public key, waiting for reply. linux37: Received host key, type 'ssh-dss'. linux37: Host 'netli01' is known and matches the host key. linux37: Computing shared secret key. linux37: Verifying server signature. linux37: Waiting for NEWKEYS message. linux37: Send NEWKEYS. linux37: Enabling encryption/MAC/compression. linux37: Sending request for user-authentication service. linux37: Service accepted: ssh-userauth. linux37: Trying empty user-authentication request. linux37: Authentication methods that can continue: publickey,gssapi-wi +th-mic,password. linux37: Next method to try is publickey. linux37: Next method to try is password. linux37: Trying password authentication. linux37: Login completed, opening dummy shell channel. linux37: channel 0: new [client-session] linux37: Requesting channel_open for channel 0. linux37: channel 0: open confirm rwindow 0 rmax 32768 linux37: Got channel open confirmation, requesting shell. linux37: Requesting service shell on channel 0. linux37: channel 1: new [client-session] linux37: Requesting channel_open for channel 1. linux37: Entering interactive session. linux37: Sending command: source /home/venkatas/.cshrc; setenv DISPLAY linux37:0; /usr/local/lsf7.0/7.0/linux2.6-glibc2.3-x86/bin/bsub -q linux64_idc_1g + xterm linux37: Sending command: source /home/venkatas/.cshrc; setenv DISPLAY linux37:0; /usr/local/lsf7.0/7.0/linux2.6-glibc2.3-x86/bin/bsub -q linux64_idc_1g + xterm linux37: Requesting service exec on channel 1. linux37: channel 1: open confirm rwindow 0 rmax 32768 ** Standard Error - I received this: LD_LIBRARY_PATH: Undefined variable. ** Standard Error - I received this: LD_LIBRARY_PATH: Undefined variable. ** Standard Error - I received this: linux37: channel 1: rcvd eof linux37: channel 1: output open -> drain linux37: input_channel_request: rtype exit-status reply 0 linux37: channel 1: rcvd close linux37: channel 1: input open -> closed linux37: channel 1: close_read lsb_init: ** Standard Error - I received this: Failed in an LSF library call: Unable to open file lsf.conf. Job not s +ubmitted. linux37: channel 1: obuf empty linux37: channel 1: output drain -> closed linux37: channel 1: close_write linux37: channel 1: send close linux37: channel 1: full closed

        Please help me out in this

        Thanks in advance