打印远程机器输出

发布于 2025-02-10 19:32:49 字数 346 浏览 2 评论 0原文

我有一个脚本

ssh node1 "systemctl stop a1"
ssh node2 "systemctl stop a2"
ssh node3 "systemctl stop a3"
ssh node4 "systemctl stop a*"
ssh node5 "systemctl stop a1*"
ssh node6 "systemctl stop a3*"

可以完成工作,但是我想在运行脚本的机器上登录SystemCtl命令的输出。是否可以?还有指针吗?

echo $?将打印代码,任何方法以获取内容或将其存储在远程计算机中并通过另一个命令进行验证。

I have a script

ssh node1 "systemctl stop a1"
ssh node2 "systemctl stop a2"
ssh node3 "systemctl stop a3"
ssh node4 "systemctl stop a*"
ssh node5 "systemctl stop a1*"
ssh node6 "systemctl stop a3*"

It does the job, but I would like to get the output of systemctl command logged on the machine where I run the script. Is it possible? And any pointers?

echo $? will print the code, any way to get the contents or any way to store it in the remote machine and verify via another command.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┈┾☆殇 2025-02-17 19:32:49

您可以将命令的输出输出,然后将输出重定向到远程计算机上的文本文件中。

例子:
ssh node1“ systemctl stop a1”>> log.txt

其中log.txt是日志文本文件,其中将存储命令的输出以及'>''操作员每次运行命令时都会将文件的OUPUT放在新行中。

请小心不要放置'>'操作员只是覆盖log.txt中的先前写的文本。

希望这有帮助!

You could pipe the output of your commands and simply redirect the output in a text file on the remote machine.

Example:
ssh node1 "systemctl stop a1" >> log.txt

Where log.txt is the log text file where the output of your command will be stored and the '>>' operator puts the ouput of the file in a new line every single time a command is run.

Be careful not to put the '>' operator as it simply overwrites the previously written text in the log.txt.

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文