打印远程机器输出
我有一个脚本
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将命令的输出输出,然后将输出重定向到远程计算机上的文本文件中。
例子:
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!