You need to start learning shell programming from scratch. Perhaps the bash guide in my signature will help (the bash scripting link is broken).
You need to:
1. run a loop reading one kine after the other from the file e.g.
Code:
total=0
while read IPADDRESS
do
.... here you process IPADDRESS
done < ipaddress-file
2. In the loop, run
whatmask on the IP address and process its ouput
Code:
whatmask $IPADDRESS | grep ^Usable | awk -F: ‘{ print $2 }’
This code gets the line that starts with
Usable.
awk then prints the second field of that line, where fields are delimited by a colon.
3. Get the number of usable IP addresses from step 2 and add it up. This is complicated by the fact that whatmask uses commas to structure large numbers like 8,192.
Code:
nip=$(whatmask $IPADDRESS | grep ^Usable | awk -F: ‘{ print $2 }’ | sed ‘s/,//‘)
total=$((total+nip))
This gets the output of the pipeline inside $(...) and assigns it to
nip.
The
sed command removes commas. It could also be done inside the
awk command, but I don’t know the required manipulations by heart.
The second line sums it up. Dollar signs are not needed inside the double parentheses.
This is not tested.