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?
我想使用ssh在几台机器上运行一些命令。我知道只需使用命令“ssh user @ hostname”即可完成。但是,我想要运行的命令在控制台上打印一些字符串。有没有办法将所有字符串发送回我正在使用的控制台?
5 个解决方案
#1
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.
然后,您可以从屏幕上分离(Ctrl-D),让它运行不管它运行多久,然后重新连接(屏幕-r test)到屏幕上并查看所有输出。但是,假设您不会从命令中获得大量输出。这是屏幕上教程的链接。
#2
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
就是这样。如果'command'输出某些内容,它将显示在您运行ssh的终端上。尝试例如ssh user @ hostname ls -l
But as others have said, GNU screen is invaluable for this type of work.
但正如其他人所说,GNU屏幕对于这类工作是非常宝贵的。
#3
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.
您可能想要使用Gnu Screen。您可以在“虚拟”终端中启动进程,“分离”终端并注销您想要的时间...然后您可以重新连接并重新连接终端以查看控制台输出。
#4
Also have a look at nohup
, for example:
还要看看nohup,例如:
ssh user@domain.com nohup script_that_outputs_strings.py > the_strings.txt
ssh user@domain.com 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.
然后,如果要返回并监视进度,可以检查并拖尾文件或将输出scp返回到本地计算机。
#5
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!
你为什么不给你发回电子邮件?或使用日志文件,并将其scp到您当前的计算机?否则,我不知道!
#1
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.
然后,您可以从屏幕上分离(Ctrl-D),让它运行不管它运行多久,然后重新连接(屏幕-r test)到屏幕上并查看所有输出。但是,假设您不会从命令中获得大量输出。这是屏幕上教程的链接。
#2
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
就是这样。如果'command'输出某些内容,它将显示在您运行ssh的终端上。尝试例如ssh user @ hostname ls -l
But as others have said, GNU screen is invaluable for this type of work.
但正如其他人所说,GNU屏幕对于这类工作是非常宝贵的。
#3
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.
您可能想要使用Gnu Screen。您可以在“虚拟”终端中启动进程,“分离”终端并注销您想要的时间...然后您可以重新连接并重新连接终端以查看控制台输出。
#4
Also have a look at nohup
, for example:
还要看看nohup,例如:
ssh user@domain.com nohup script_that_outputs_strings.py > the_strings.txt
ssh user@domain.com 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.
然后,如果要返回并监视进度,可以检查并拖尾文件或将输出scp返回到本地计算机。
#5
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!
你为什么不给你发回电子邮件?或使用日志文件,并将其scp到您当前的计算机?否则,我不知道!