From 84d82932ad5d20fba956d85c903705ff2f2c6a7a Mon Sep 17 00:00:00 2001 From: mitty Date: Mon, 6 Jul 2009 05:49:54 +0000 Subject: [PATCH] * FIX: use 'tr' to replace repeated SPACE with a single SPACE before 'cut' lines git-svn-id: https://lab.mitty.jp/svn/lab/trunk@14 7d2118f6-f56c-43e7-95a2-4bb3031d96e7 --- iproute/setroute-rhel.sh | 20 ++++++++++---------- iproute/setroute.sh | 10 +++++----- iptables/setnapt.sh | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/iproute/setroute-rhel.sh b/iproute/setroute-rhel.sh index e88bdc6..9314dd9 100755 --- a/iproute/setroute-rhel.sh +++ b/iproute/setroute-rhel.sh @@ -2,10 +2,10 @@ set -x -IF="${1:?"usage: $0 [gateway] "}" +IFACE="${1:?"usage: $0 [gateway] "}" GATEWAY=$2 -TID=`/sbin/ip addr show dev ${IF} | grep -w ${IF}: | cut -d : -f 1` +TID=`/sbin/ip addr show dev ${IFACE} | grep -w ${IFACE}: | tr -s ' ' | cut -d : -f 1` if [ "${GATEWAY}" = "down" ]; then # delete routing table and policy and exit @@ -14,30 +14,30 @@ if [ "${GATEWAY}" = "down" ]; then ## device has no longer any IP addr, so do not use IPADDR /sbin/ip rule del table ${TID} priority ${TID} /sbin/ip route flush cache - echo "remove routing table and policy for ${IF}" + echo "remove routing table and policy for ${IFACE}" exit fi # get IP address, network mask, default gateway info -IPADDR=`/sbin/ip addr show dev ${IF} | grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1` -NETWORK=`/sbin/ip route show dev ${IF} | 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` +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 ${IF} | 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 # set routing table -/sbin/ip route add ${NETWORK} dev ${IF} table ${TID} -/sbin/ip route add default via ${GATEWAY} dev ${IF} table ${TID} +/sbin/ip route add ${NETWORK} dev ${IFACE} table ${TID} +/sbin/ip route add default via ${GATEWAY} dev ${IFACE} table ${TID} # set routing policy /sbin/ip rule add from ${IPADDR} table ${TID} priority ${TID} /sbin/ip route flush cache -echo "add routing table and policy for ${IF} on table ${TID}" +echo "add routing table and policy for ${IFACE} on table ${TID}" diff --git a/iproute/setroute.sh b/iproute/setroute.sh index 2ff477e..59102fa 100755 --- a/iproute/setroute.sh +++ b/iproute/setroute.sh @@ -15,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 @@ -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 diff --git a/iptables/setnapt.sh b/iptables/setnapt.sh index 6093f6d..5626c6c 100755 --- a/iptables/setnapt.sh +++ b/iptables/setnapt.sh @@ -30,7 +30,7 @@ fi sleep 60 if [ -z "${GATEWAYS}" ]; then - GATEWAYS=`/sbin/ip route show table main | grep -w default | cut -d ' ' -f 5` + GATEWAYS=`/sbin/ip route show table main | grep -w default | tr -s ' ' | cut -d ' ' -f 5` fi for GW in ${GATEWAYS}; do @@ -39,7 +39,7 @@ for GW in ${GATEWAYS}; do continue fi - IPADDR=`/sbin/ip addr show dev ${GW} | grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1` + IPADDR=`/sbin/ip addr show dev ${GW} | grep -w inet | tr -s ' ' | cut -d ' ' -f 3 | cut -d / -f 1` if [ -z "${IPADDR}" ]; then # device doesn't seem to have an IP address continue -- 1.7.9.5