Holy Monks,

I am using the Net::SSH::Perl module to run commands on a remote linux server (located in the same LAN). It appears to me that I am having a timing problem. The relevant part of my code looks like this:

my $cmd = Generate_Command($arg1,$arg2); $ssh->cmd($cmd); $cmd = Generate_Another_Command($arg1,$arg2); $ssh->cmd($cmd);
The execution time of the command on the remote server varies with what arguments are passed. For e.g, if DES encryption is required, it takes about 1 min and if RSA is used it takes 10 mins.

The problem I am facing is that perl seems to execute the next line of code without the first command over ssh running to completion. As a result, the second command over ssh fails (as it depends on the first). Is there a workaround for this problem? I tried implementing a solution with fork() where the SSH stuff runs in the child and the parent waits for it to complete, but this hasn't worked for me either. Can someone suggest an efficient method to wait for the command on the remote to server to return before moving on to the next line of code?

The command I run on the server is a shell script executes a few java classes. It looks something like this:

#! export CLASSPATH=/usr/local/classes/classes12.zip PATH=/usr/local/java/bin:$PATH export LD_LIBRARY_PATH=/usr/local/tonga/lib /usr/local/tonga/bin/javadb dbVersion $1
Thanks a lot,
linuxfan Update: All monks,

Thanks for your suggestions. I am working on the script now and will post any updates as soon as I find them.


In reply to How to hold execution of perl script while it runs command on remote machine by linuxfan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.