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

D

Dune

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!
 
J

J. Gleixner

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.
 
B

Brian McCauley

Dune said:
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?
 
D

Dune

J. Gleixner said:
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!
 
J

J. Gleixner

Dune said:
J. Gleixner said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top