Closed. This question is off-topic。它当前不接受答案。
想改善这个问题吗? Update the question,所以它是用于堆栈溢出的on-topic。
已关闭8年。
Improve this question
我需要通过SSH访问多个主机,执行特定命令(
我想使用
我的问题是将输出保存到文本文件并同时循环运行约100台计算机。
要针对多个主机执行此操作,建议您使用ssh-agent并设置自定义密钥:
想改善这个问题吗? Update the question,所以它是用于堆栈溢出的on-topic。
已关闭8年。
Improve this question
我需要通过SSH访问多个主机,执行特定命令(
show ms info
)并将输出捕获到文件中。我需要将该文件复制回我的Linux机器我想使用
ssh
和expect
提供密码我的问题是将输出保存到文本文件并同时循环运行约100台计算机。
最佳答案
它比您想象的更直接:
host1 $ ssh user@host2 ls > remote-output.txt
Enter passphrase for key '/home/user/.ssh/id_rsa':
host1 $ ls
remote-output.txt
host1 $
要针对多个主机执行此操作,建议您使用ssh-agent并设置自定义密钥:
$ ssh-agent bash
$ ssh-add
Enter passphrase for /home/user/.ssh/id_rsa:
$ for h in host1 host2;do ssh $h ls > $h.txt; done
$ ls
host1.txt host2.txt
$