I'm trying to construct a script that will run a command using the contents of two files, and append the results of that command to another file.
My two files:
nameservers
- contains the addresses of my DNS.hostnames
- contains hostnames that needs to be resolved against the nameservers.
I need to pass the contents of nameservers
and hostnames
to this command:
dig @[content of nameservers file] -t a [content of hostnames]
Then each run it will extract the query time value and append it into a file in the following format:
[nameserver1] [query time value]
Like:
1.1.1.1 100
2.2.2.2 120
3.3.3.3 115
Answer
here is a way:
#!/bin/bash
hostnames=`cat hostnamesfile`
cat nameserversfile | while read n; do
echo "$hostnames" | while read h; do
echo -n "$n "
dig @$n -t a $h | grep 'Query time' | grep -o '[0-9]\+'
done
done > resultsfile
No comments:
Post a Comment