I have a loop setup to feed in a file with a list of IP's. The loop will search through a file using the IP's to get the associated MAC address. Sometimes for each IP there will be more than one MAC listed for it. It could be one or it could be seven or more. That is really an unknown. All I know is I need to be able to compare how ever many MAC's are reported for each IP and echo something if they do not all match. Here is what my script output looks like now:
Testing 192.168.17.25
00:0f:XX:41:e7:50; 00:0f:XX:41:e7:50; 00:0f:XX:41:e7:50;
Testing 192.168.17.26
00:0f:XX:43:7a:f0; 00:0f:XX:43:7a:f0; 00:0f:XX:43:7a:f0; 00:0f:XX:43:7a:f0;
And here is my while loop:
cat $list | while read line;
do
echo "Testing $line"
var=$(/bin/grep -A 10 -w $line $file | /bin/grep 'ethernet' | /bin/awk '{print $3}')
echo $var
done
How can I construct an if/then to go inside the loop to compare the MAC addresses and echo a message if it finds one that is different?
UPDATE: The $list file is a simple text file with IP's.
192.168.17.1
192.168.17.2
etc...
The $file I am running the IP's through to get the MAC is a DHCP lease file.
lease 192.168.17.28 {
starts 2 2016/07/12 07:36:15;
ends 3 2016/07/13 07:36:15;
tstp 3 2016/07/13 07:36:15;
tsfp 3 2016/07/13 19:36:15;
atsfp 3 2016/07/13 19:36:15;
cltt 2 2016/07/12 07:36:15;
binding state free;
hardware ethernet 84:7b:eb:24:87:ef;
uid "\001\204{\353$\207\357";
Aucun commentaire:
Enregistrer un commentaire