2

I need to access to multiple hosts through SSH, execute a specific command (show ms info) and capture the output to a file. I need to copy that file back to my linux machine

I want to use ssh and expect to supply the password

My problem is saving the output to a text file and looping around 100 machines simultaneously.

KurzedMetal
  • 12,540
  • 6
  • 39
  • 65
  • If you can use Perl, check [Net::OpenSSH::Parallel](https://metacpan.org/module/Net::OpenSSH::Parallel). – salva May 23 '12 at 09:13

1 Answers1

4

It is more straightforward than you think:

host1 $ ssh user@host2 ls > remote-output.txt
Enter passphrase for key '/home/user/.ssh/id_rsa':
host1 $ ls
remote-output.txt
host1 $

To do it for multiple hosts, I suggest using ssh-agent and setting up autorization keys:

$ 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
$
Anders Lindahl
  • 41,582
  • 9
  • 89
  • 93