tags:

views:

618

answers:

5

i want to run some command on several machine using ssh. I know it can be done by just using the command "ssh user@hostname command". However, the command i want to run print some string on the console. Is there any way that send all the strings back to the console that i'm on?

A: 

Why don't you send you an email back? Or use a log file, and scp it to your current computer? otherwise, I don't know!

Aif
the program i want to run remotely may take several day. I just want to be able to monitor the live progress.
CKeven
+3  A: 

You could run the commands in a screen:

screen -S test
ssh user@hostname command1
ssh user@hostname2 command2

You can then detach (Ctrl-D) from the screen, let it run for however long it will run, then re-attach (screen -r test) to the screen and see all of the output. This assumes that you won't have a ton of output from the commands, however. Here's a link to a tutorial on screen.

Dan Wolchonok
don't you first want to connect to the remote host, then start a screen session there, /then/ executing the command?
MSpreij
I don't think so. As I understand the question, you want all of the output on one console, so that's why you start the screen and then run the commands.
Dan Wolchonok
What if i do have a tons of output on one console. How big is the buffer?
CKeven
If there is tons of output on the console, I would write the output to a standard location on each of the machines, and then copy the files from each host to a central location to look at the logs.
Dan Wolchonok
The number of lines of output stored is set up in your ~/.screenrc file in a line such as: " defscrollback 15000 " to store 15000 lines per window.
Mark Rushakoff
i run the command you mentioned above. the output of the command is not on the screen that newly created. Instead, it's on the main window that i'm running the shell script from. Did you do something wrong?
CKeven
+1  A: 

You probably want to use Gnu Screen for this. You can start a process in a "virtual" terminal, "detach" the terminal and log out for however long you want... Then you can ssh back in and re-attach the terminal to see the console output.

Mark Rushakoff
+2  A: 
 ssh user@hostname command

Does just that. if 'command' outputs something, it'll show on the terminal you ran ssh from. Try e.g. ssh user@hostname ls -l

But as others have said, GNU screen is invaluable for this type of work.

nos
A: 

Also have a look at nohup, for example:

ssh [email protected] nohup script_that_outputs_strings.py > the_strings.txt

Then if you want to go back and monitor the progress, you could check back and tail the file or scp the output back to your local machine.

bvmou