> # ip addr show eth0 > 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state > UP qlen 1000 > link/ether 00:1e:4f:f8:00:39 brd ff:ff:ff:ff:ff:ff > inet 172.16.24.1/24 brd 172.16.24.255 scope global eth0 > inet 172.16.24.2/24 brd 172.16.24.255 scope global secondary eth0 > inet 172.16.24.3/24 brd 172.16.24.255 scope global secondary eth0 > inet 172.16.24.4/24 brd 172.16.24.255 scope global secondary eth0 > inet 172.16.24.6/24 brd 172.16.24.255 scope global secondary eth0 > inet 172.16.24.8/24 brd 172.16.24.255 scope global secondary eth0 > .... > > All of them have a broadcast address of 172.16.24.255 That means that the > grep will match when the last octet of the address I'm trying to bring up > (or down) is 2 or 25, and the test will fall through to the message "Cannot > add IPv4 address ${IP} to ${1}. Already present." even though the address > is NOT present in reality. > > This is not good behavior. It should only be looking at the second field, > not the whole line. The ideal solution would probably be to filter it with > awk, but after a little perusal, I came up with a simpler solution. This > is what the grep should look like: > > if [ "$(ip addr show ${1} | grep ${IP}/)" == "" ]; then > > Note the addition of a slash after the IP (the separator for the netmask.) > That makes sure it's checking the correct IP address field. I've tested > this, and it works.
This is a pretty rare corner case, but the fix looks right. I'll update the script. Technically there could also be an error if the IP address in the ifconfig file is specified with leading zeros, e.g. 172.016.024.008, but I'll ignore that for now. -- Bruce -- http://linuxfromscratch.org/mailman/listinfo/lfs-dev FAQ: http://www.linuxfromscratch.org/faq/ Unsubscribe: See the above information page