![]() |
Perl: Wait for ssh connection to close
I'm trying to get my perl script to execute a command (using ssh) on a remote computer, and keep the connection open until the job is finished.
To illustrate, say I execute the following code: Code:
foreach $machine (@machines) { As of now, emacs is executed, but the connection is closed as soon as the command is issued on the remote program. Is want the connection to stay open until the actual application closes. How can this be accomplised? |
Re: Perl: Wait for ssh connection to close
The ampersand (bold below) puts the job in the background:
Code:
system("xterm -e ssh $machine 'emacs' &");Code:
xterm &Maybe you want to elaborate on what you intend to happen. |
I added the "&" on purpose so that the xterm would run in the background. My fist post was not very precise, so let my try again. :)
My aim is to automate this: 1) log onto the remote machines (using ssh) in xterms, one xterm pr machine/connection 2) run a program (for example emacs) 3) when the program exits, close the ssh connection and exit the script In essence: How do I open, say, 3 xterms at once, each having logged onto a different machine, and the xterms run a remote program (i.e. emacs) and are not closed until the program has finished? Did this make it more clear? |
Still more questions: Why do you use xterm? Does ssh require a password? Do you tunnel X11, or should emacs run in the xterm, like "emacs -nw"?
Do you need the perl script to wait till all emacses and their xterms exit? One answer: ssh -t |
The following will open all windows (and exit).
Code:
my @machines = qw(a b c);I'm aware that that violates your aim Quote:
|
I'm using ssh-keys to authenticate my machine to the remote machines. These machines doen't have X installed, as they as just "slaves" which are to run a distributed program. I use xterm so that I can have one ssh connection pr xterm window, and communicate with these machines through the terminals. Is there another, better way of doing this?
The perl script need not wait till the xterms exit, as long as these xterms maintains the ssh-connection. I thought the xterms would exit automatically when the script ended, but I guess I was wrong. So never mind that last aim. :) I'll try the "-t" option and see if it help. Thanks for the help so far! |
Why not fork for each machine and then waitpid in the main script after your loop.
|
I thought about it, but as this script is my very first perl-script I don't know how to do it + I figured I'd try without forking.
Could you provide me a link to some example code for forking in perl? |
You should just need to use:
Code:
foreach $machine (@machines){http://search.cpan.org/~jhi/perl-5.8.0/pod/perlfork.pod |
Okay, thanks! I'll check it out!
|
| All times are GMT -5. The time now is 08:13 PM. |