Question: I am completely new to scripting and am having some trouble piecing this together from some other online resources.

What I want to do is run a bash script that will grep for a keyword domain in the /etc/hosts file on multiple servers. In the output file, I am looking for a list of the servers that contain this keyword but am not looking to make any changes. Simply looking for which machines have this value. Since there are a bunch of machines in question, listing the servers I am looking to search for won't work, but the machine I am doing this from does have SSH keys for all of the ones in question.

I have a listing of the servers I want to query in three files on the machine (one for each environment) I am going to run this script from.

```
Linux.prod.dat
Linux.qa.dat
Linux.dev.dat

```

Each file is simply a list of server names in the environment. For example..

```
server1
server2
server3 
etc...

```

I am totally lost here and would appreciate any help.

Answer: 
Here is an example:

```
KEYWORD=foo
SERVERLIST=Linux.prod.dat
OUTPUTLIST=output.dat

for host in $(cat ${SERVERLIST}); do
    if [[ -n "$(ssh ${host} grep '${KEYWORD}' /etc/hosts && echo Y)" ]]; then
        echo ${host} >> ${OUTPUTLIST}
    fi
done

```
Try GNU parallel

```
parallel --tag ssh {} grep -l "KEYWORD" /etc/hosts :::: Linux.prod.dat

```

`parallel` run command multiple times substituting`{}`with lines from `Linux.prod.dat` file.
`--tag` switch adds value from the Linux.prod.dat on the beginning of the file. So, the output of the command will look like:

```
server1 /etc/hosts
server5 /etc/hosts
server7 /etc/hosts

```

Where server1, server5, etc. will be names of the servers where `/etc/hosts` contains `KEYWORD`