Saturday, 7 October 2017

dig - Feed Content of a File to a Bash Script





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:





  1. nameservers - contains the addresses of my DNS.

  2. 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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...