Help: how to run programs on a remote machine with Perl script...

Discussion in 'Perl Misc' started by Dune, Jun 2, 2006.

  1. Dune

    Dune Guest

    I have a question about ow to write Perl script to run a remote program
    on a remote server and automatically obtain the results. My situation
    is as follows:

    My program is a C++ one running on a local Linux box( Rednat 8.0). In
    the middle of execution, I need to run an optimization package on a
    remote IBM-AIX machine in Supercomputer Center. The optimization
    package is generally run by a command line on that IBM-AIX machine
    (maybe it also can be evoked by library call---I am not sure), and I
    have an account on the IBM-AIX machine. My program can not be compiled
    on the IBM-AIX machine as it needs to call another pre-compiled
    library, which can only be used under Linux & gcc2.95.3.

    So I would like to achieve this by call a Perl script in my C++
    program, and the Perl script will do the following:

    1. My main program generates the input file to optimization.
    2. My main program call the Perl script and do the following:
    2.1 sftp to the IBM-AIX machine, and put the optimization
    input file to the server.
    2.2 ssh to the IBM-AIX machine, and execute the optimization
    package with the input using command line.
    2.3 check when the optimization finishs, and
    3.4 sftp to the IBM-AIX machine, and get the output result
    file.

    Duing the execution, my main program will wait for the result from
    optimization package, and then make use of the results once it is
    available.

    I am not very familiar with Perl, and would like to have your guys'
    kind suggestion about which Perl package/component can help me do this?
    Is the above procedures feasible? Is there any example or template I
    can learn from?

    Thanks a lot for your help!
     
    Dune, Jun 2, 2006
    #1
    1. Advertising

  2. Dune

    J. Gleixner Guest

    Dune wrote:
    [...]
    > So I would like to achieve this by call a Perl script in my C++
    > program, and the Perl script will do the following:
    >
    > 1. My main program generates the input file to optimization.
    > 2. My main program call the Perl script and do the following:
    > 2.1 sftp to the IBM-AIX machine, and put the optimization
    > input file to the server.
    > 2.2 ssh to the IBM-AIX machine, and execute the optimization
    > package with the input using command line.
    > 2.3 check when the optimization finishs, and
    > 3.4 sftp to the IBM-AIX machine, and get the output result
    > file.
    >
    > Duing the execution, my main program will wait for the result from
    > optimization package, and then make use of the results once it is
    > available.
    >
    > I am not very familiar with Perl, and would like to have your guys'
    > kind suggestion about which Perl package/component can help me do this?
    > Is the above procedures feasible? Is there any example or template I
    > can learn from?


    If you know shell scripting, that would probably be much easier,
    compared to learning and using perl.

    If you want to go with perl, for whatever reason, search CPAN
    (http://search.cpan.org/) for Net::SSH and Net::SFTP. Read their
    documentation, install them, and give it a try. In addition, you may
    also want to look at the Expect module, which is also available on CPAN.
     
    J. Gleixner, Jun 2, 2006
    #2
    1. Advertising

  3. Dune wrote:
    > I have a question about ow to write Perl script to run a remote program
    > on a remote server and automatically obtain the results.


    > So I would like to achieve this by call a Perl script in my C++
    > program, and the Perl script will do the following:
    >
    > 1. My main program generates the input file to optimization.
    > 2. My main program call the Perl script and do the following:
    > 2.1 sftp to the IBM-AIX machine, and put the optimization
    > input file to the server.
    > 2.2 ssh to the IBM-AIX machine, and execute the optimization
    > package with the input using command line.
    > 2.3 check when the optimization finishs, and
    > 3.4 sftp to the IBM-AIX machine, and get the output result
    > file.


    Is there some reason why you can just do:

    my $process_output = `ssh blah blah blah`;

    Where blah blah blah, are the switches and arguments that ssh needs to
    run the specified program on the specified server?
     
    Brian McCauley, Jun 2, 2006
    #3
  4. Dune

    Dune Guest

    J. Gleixner wrote:
    > Dune wrote:
    > [...]
    > > So I would like to achieve this by call a Perl script in my C++
    > > program, and the Perl script will do the following:
    > >
    > > 1. My main program generates the input file to optimization.
    > > 2. My main program call the Perl script and do the following:
    > > 2.1 sftp to the IBM-AIX machine, and put the optimization
    > > input file to the server.
    > > 2.2 ssh to the IBM-AIX machine, and execute the optimization
    > > package with the input using command line.
    > > 2.3 check when the optimization finishs, and
    > > 3.4 sftp to the IBM-AIX machine, and get the output result
    > > file.
    > >
    > > Duing the execution, my main program will wait for the result from
    > > optimization package, and then make use of the results once it is
    > > available.
    > >
    > > I am not very familiar with Perl, and would like to have your guys'
    > > kind suggestion about which Perl package/component can help me do this?
    > > Is the above procedures feasible? Is there any example or template I
    > > can learn from?

    >
    > If you know shell scripting, that would probably be much easier,
    > compared to learning and using perl.
    >
    > If you want to go with perl, for whatever reason, search CPAN
    > (http://search.cpan.org/) for Net::SSH and Net::SFTP. Read their
    > documentation, install them, and give it a try. In addition, you may
    > also want to look at the Expect module, which is also available on CPAN.


    Thanks a lot! Could you please give a little bit more details about how
    to write such shell script? e.g., how to monitor that the optimizator
    on the server has finished task (keep checking or is there any signal)?
    how to supply the password while ssh/sftp in Perl/shell script ?
    Thanks a lot!
     
    Dune, Jun 2, 2006
    #4
  5. Dune

    J. Gleixner Guest

    Dune wrote:
    > J. Gleixner wrote:
    >> Dune wrote:

    [...]
    >>> I am not very familiar with Perl, and would like to have your guys'
    >>> kind suggestion about which Perl package/component can help me do this?
    >>> Is the above procedures feasible? Is there any example or template I
    >>> can learn from?

    >> If you know shell scripting, that would probably be much easier,
    >> compared to learning and using perl.
    >>
    >> If you want to go with perl, for whatever reason, search CPAN
    >> (http://search.cpan.org/) for Net::SSH and Net::SFTP. Read their
    >> documentation, install them, and give it a try. In addition, you may
    >> also want to look at the Expect module, which is also available on CPAN.

    >
    > Thanks a lot! Could you please give a little bit more details about how
    > to write such shell script?


    Not on a perl newsgroup. Look around the Internet for Korn Shell (ksh),
    or C-Shell (csh) scripting; your *nix system should have one of those
    installed already, or talk with your System Administrator about what
    shells are available for you.

    >e.g., how to monitor that the optimizator
    > on the server has finished task (keep checking or is there any signal)?


    That'd be up to you. Simply waiting for ssh to exit and getting the
    resulting file should be fine.

    > how to supply the password while ssh/sftp in Perl/shell script ?


    Ahhh.. from the Net::SSH documentation..

    FREQUENTLY ASKED QUESTIONS ^

    Q: How do you supply a password to connect with ssh within a perl script
    using the Net::SSH module?

    A: You don't. Use RSA or DSA keys. See the ssh-keygen(1) manpage.
     
    J. Gleixner, Jun 2, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,831
  2. johnny
    Replies:
    5
    Views:
    532
    Antonio Cuni
    Jul 11, 2007
  3. Tim Golden
    Replies:
    0
    Views:
    1,132
    Tim Golden
    Feb 9, 2008
  4. Tim Golden
    Replies:
    0
    Views:
    394
    Tim Golden
    Feb 9, 2008
  5. hara
    Replies:
    6
    Views:
    168
    Peter Scott
    May 27, 2006
Loading...

Share This Page