Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running command on remote machine using ssh

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?

like image 715
Progress Programmer Avatar asked Feb 20 '26 11:02

Progress Programmer


2 Answers

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.

like image 73
Dan Wolchonok Avatar answered Feb 22 '26 01:02

Dan Wolchonok


 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.

like image 37
nos Avatar answered Feb 22 '26 00:02

nos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!