2

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

我想使用sshexpect提供密码

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

4

1 回答 1

4

它比你想象的更简单:

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
$
于 2012-05-22T11:50:27.440 回答