This one was easy, first create a file (hosts_ip.txt) with the IP of each server to get its /etc/hosts:

Generate a private/public pair key and add the public one in authorized_keys of each server :

# generate public/private key
ssh-keygen -t rsa -b 2048

#enable public key in server
cat >> ~/.ssh/authorized_keys

Copy the private keys to a common directory, in this case «/home/mortiz/get_hosts/pass_<server_ip>» and with some shell the magic happens:


# Lee el archivo de IP's y descarga de cada equipo /etc/hosts

cat /home/mortiz/get_hosts/hosts_ip.txt | while read -r g; do

scp -q -i /home/mortiz/get_hosts/pass_$g <username>@$g:/etc/hosts /cygdrive/g/resources/etc_hosts/$(date +%Y-%m-%d)_hosts_$g

That’s it.