This morning I could not for the life of me remember how to read two variables from one line in bash. As a result I am putting this simple script up here so that I have an easy place to reference.
The input file was a listing of printer IP addresses that are translated is in the file /tmp/printers.txt and looks like this.
192.168.1.10 = 10.0.1.10
192.168.50.5 = 10.0.1.11
192.168.50.15 = 10.0.1.25
Here is the simple code to read both variables.
# 2010-08-24 Jud Bishop
# Simple script to find names of local and remote printers
# that are translated.
while IFS== read remote local
name=`dig +short -x $local`
echo -e "$name,$remote,$local"
done < /tmp/printers.txt
But it came it out in this format, not much of a problem but I prefer it more legible.
tcp5.chainringcircus.org.,192.168.1.10 , 10.0.1.10
rmp7.chainringcircus.org.,192.168.50.5 , 10.0.1.11
jlb3.chainringcircus.org.,192.168.50.15 , 10.0.1.25
So I cleaned up the output. The first sed stanza deletes the third “.” in the output and the second sed stanza deletes the spaces.
./find-printers.sh | sed 's/\.//3