【问题标题】:Executing remote command and saving input to file [closed]执行远程命令并将输入保存到文件[关闭]
【发布时间】:2012-05-28 21:42:49
【问题描述】:

我需要通过 SSH 访问多个主机,执行特定命令 (show ms info) 并将输出捕获到文件中。我需要将该文件复制回我的 linux 机器

我想使用sshexpect 来提供密码

我的问题是将输出保存到一个文本文件并同时循环大约 100 台机器。

【问题讨论】:

标签: linux shell ssh telnet remote-execution


【解决方案1】:

比你想象的要简单:

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
$

【讨论】:

  • 非常感谢!!多台主机仍然存在问题,但它或多或少来自机器
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-02
相关资源
最近更新 更多