I have a csv file which has the list of the following ip addresses:
SSH IP NFS IP iSCSI IP
10.xxx.xxx.aaa 172.xxx.xxx.aaa 172.yyy.xxx.aaa
10.xxx.xxx.bbb 172.xxx.xxx.bbb 172.yyy.xxx.bbb
10.xxx.xxx.ccc 172.xxx.xxx.ccc 172.yyy.xxx.ccc
10.xxx.xxx.ddd 172.xxx.xxx.ddd 172.yyy.xxx.ddd
... ... ...
... ... ...
I want to compare the last octets in SSH IP, NFS IP and iSCSI IP and if they match, i want to execute a few commands, by ssh'ing into the box.
I want to know the most efficient way to compare the last octets, considering my case. Any help around this would be highly appreciated.
P.S. I do not have any problems in ssh'ing into the box, i am planning to use the paramiko library.
One simple way would be to use the Python CSV library to import the data a row at a time. Then to use a list comprehension to split the IP address into components, taking the last one and adding it to a set. If the set results in a length of 1, you know all columns are the same.
I am assuming the above data shows the CSV file, and is tab delimited:
If you are looking for the fastest solution, I strongly suggest you time any regular expression solution against this code to determine which is the best, as it not always obvious which would be best.
If your CSV file is in a different format, it would simply need an additional list comprehension step to convert it to how the data is shown above.