Simple Script

This morning I could not for the life of me remember how to read two variables from on line in bash. As a result I am putting this simple script up here.

The listing of printer IP addresses is in the file /tmp/printers.txt and looks like this.

cat /tmp/printers.txt
192.168.1.10 = 10.0.1.10
192.168.50.5 = 10.0.1.11
192.168.50.15 = 10.0.1.25

[code lang=”bash”]
#!/bin/bash
# 2010-08-24 Jud Bishop
# Simple script to find names of local and remote printers
# that are translated.

while IFS== read remote local
do
name=`dig +short -x $local`
echo -e "$name,$remote,$local"
done < /tmp/printers.txt
[/code]

pipp5.eamc.org.,172.22.24.239 , 172.22.57.201
psyp7.eamc.org.,172.22.24.197 , 172.22.57.202
psyp3.eamc.org.,172.22.24.114 , 172.22.57.203

[code]
./find-printers.sh | sed ‘s/\.//3
s/\ //g’
[/code]

This entry was posted in Code, Linux. Bookmark the permalink.

Leave a Reply