0

Problem statement: consider the present scenario, i am running some commands/code on host-1, and i need to open a tool on host-2 where i may perform some operations on data obtained on host-1.

what i was doing till now was opening two different shells, one for host 1 and another for host 2, then i after running codes on host-1 would switch manually to the other shell prompt, where i would deal with the commands on tool. and would finally move back to the original shell.

An example would be executing a basic linux command on host-2 and capturing it response. Ex: do a ls -l on host-2 while we are on host-1 and get the results in some variable that could be kept for further processing.

Is there a way to automate this thing?? I mean a way in which i can logon to host-2 on the fly and execute those tool commands and get back to host-1 ?

I prefer writing a perl script for this.

2 Answers2

0

Do you mean something like this?

#!/usr/bin/perl

use strict;
use warnings;

my @results = qx(ssh host-2 ls -l);

print @results;

Or are you looking for something more complicated?

Dave Cross
  • 68,119
  • 3
  • 51
  • 97
  • No, what i was looking for is something like: on Host-1: ....x... ....y.... ....z.... then go to host 2 and execute some commands: ...123... ...342... ...r45... ... ls -l ... etc... etc... then again go back to host-1 and run some more commands – Akshit Jain May 11 '15 at 16:31
  • I have no idea what that means. You run my program on host-1 and it shows you the results of running `ls -l` on host-2. I thought that's what you asked for. – Dave Cross May 11 '15 at 16:32
  • Please have a look at my updated comment to your answer... I will try your code as well – Akshit Jain May 11 '15 at 16:33
  • 2
    I'm pretty sure that my example gives you enough of an example that you can build on it to do what you want. Use `qx(command)` to run stuff locally. Use `qx(ssh host command)` to run stuff remotely. – Dave Cross May 11 '15 at 16:35
  • Pay attention to what @DaveCross has told you. Although, When I find my self running a lot of shell commands, I think of shell scripts. Especially in this case, because you didn't mention any post-processing of the resulting output. – Len Jaffe May 11 '15 at 16:42
0

I'd take a look at Rex:

http://www.rexify.org/

But if Python is an option, you might also like Fabric:

http://www.fabfile.org/

Bill Agee
  • 3,606
  • 20
  • 17