X-Git-Url: http://lab.mitty.jp/git/?a=blobdiff_plain;f=iproute%2Fsetroute.sh;h=b47b854dd0d78f22e6fa6ec9f4c0e15fc15979ab;hb=e1132d93be19e858e374644d81e8fc28d09e2954;hp=2ff477e2eda3bf5100bd75967e63b3c4fa90ccdf;hpb=4a36a1b26f4cdc2dc3d06d7b3c4ac895b0083b2f;p=lab.git diff --git a/iproute/setroute.sh b/iproute/setroute.sh old mode 100644 new mode 100755 index 2ff477e..b47b854 --- a/iproute/setroute.sh +++ b/iproute/setroute.sh @@ -7,15 +7,15 @@ set -x ## INTERFACES(5) # IFACE physical name of the interface being processed -# METHOD method of the interface (e.g., static) -# MODE start if run from ifup, stop if run from ifdown -# PHASE as per MODE, but with finer granularity, distinguishing the pre- -# up, post-up, pre-down and post-down phases. +# METHOD method of the interface (e.g., static) +# MODE start if run from ifup, stop if run from ifdown +# PHASE as per MODE, but with finer granularity, distinguishing the pre- +# up, post-up, pre-down and post-down phases. # optional arugument to set default gateway manually GATEWAY=$1 -TID=`/sbin/ip addr show dev ${IFACE} | grep -w ${IFACE}: | cut -d : -f 1` +TID=`/sbin/ip addr show dev ${IFACE} | grep -w ${IFACE}: | tr -s ' ' | cut -d : -f 1` if [ "${PHASE}" = "post-down" ]; then # delete routing table and policy and exit @@ -30,19 +30,19 @@ fi # get IP address, network mask, default gateway info -IPADDR=`/sbin/ip addr show dev ${IFACE} | grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1` +IPADDR=`/sbin/ip addr show dev ${IFACE} | grep -w inet | tr -s ' ' | cut -d ' ' -f 3 | cut -d / -f 1` if [ -z "${IPADDR}" ]; then # fail to bind IP address to device echo "${IFACE} has no IP address." exit fi -NETWORK=`/sbin/ip route show dev ${IFACE} | grep -w ${IPADDR} | cut -d ' ' -f 1` +NETWORK=`/sbin/ip route show dev ${IFACE} | grep -w ${IPADDR} | tr -s ' ' | cut -d ' ' -f 1` if [ -z "${GATEWAY}" ]; then - GATEWAY=`/sbin/ip route show dev ${IFACE} | grep -w default | cut -d ' ' -f 3` + GATEWAY=`/sbin/ip route show dev ${IFACE} | grep -w default | tr -s ' ' | cut -d ' ' -f 3` fi if [ -z "${GATEWAY}" ]; then - GATEWAY=`/sbin/ip route | grep -w default | cut -d ' ' -f 3` + GATEWAY=`/sbin/ip route | grep -w default | tr -s ' ' | cut -d ' ' -f 3` # this may add wrong default route especially on RHEL fi