1

This question already has an answer here:

How do I ssh into multiple hosts (e.g host1, host2, host3, etc) and cat /etc/fstab to generate report.txt?

marked as duplicate by Gilles, Anthon, slm, manatwork, Tshepang Jun 21 '13 at 9:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

You can do that like that:

for i in username1@host1 username@host2; do ssh $i cat /etc/fstab >> raport.txt; done

Provided that you have ssh public key authentication set on your hosts (host1 & host2), if not you will be prompted for password for each host.

2

Yes, you can ssh hostname command and redirect the output to your report.txt

The following script to get this report from all of your hosts. servername.dat contains all the host names.

 #!/bin/sh
 SERVERLIST=servername.dat
 ICMD='cat /etc/fstab'
 while read SERVERNAME
 do
    ssh -n $SERVERNAME $ICMD > $SERVERNAME_report.txt
 done < "$SERVERLIST"
  • 1
    you might want to use >> instead of > – Red Cricket Jun 20 '13 at 22:34
  • Yes, if required append – Raza Jun 20 '13 at 22:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.