X-Git-Url: http://lab.mitty.jp/git/?a=blobdiff_plain;f=iproute%2Fsetroute.sh;h=59102fa52401414504dcf1c5d107e0ae4896c7eb;hb=e829fd8dfc421a415a74d8719469a1a7c024e438;hp=f4939012373ec79a6e5144a060c915e755375f82;hpb=8c804d83125c275fd3c5ef8e32b002e2f785a6b3;p=lab.git diff --git a/iproute/setroute.sh b/iproute/setroute.sh old mode 100644 new mode 100755 index f493901..59102fa --- a/iproute/setroute.sh +++ b/iproute/setroute.sh @@ -1,5 +1,8 @@ #!/bin/sh +# set individualized routing table and policy for each network device + + set -x ## INTERFACES(5) @@ -12,7 +15,7 @@ set -x # 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 @@ -27,14 +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` -NETWORK=`/sbin/ip route show dev ${IFACE} | grep -w ${IPADDR} | 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} | 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