Changeset 14 in lab


Ignore:
Timestamp:
Jul 6, 2009 2:49:54 PM (15 years ago)
Author:
mitty
Message:
  • FIX: use 'tr' to replace repeated SPACE with a single SPACE before 'cut' lines
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/iproute/setroute-rhel.sh

    r10 r14  
    33set -x 
    44 
    5 IF="${1:?"usage: $0 <ether_device> [gateway] "}" 
     5IFACE="${1:?"usage: $0 <ether_device> [gateway] "}" 
    66GATEWAY=$2 
    77 
    8 TID=`/sbin/ip addr show dev ${IF} | grep -w ${IF}: | cut -d : -f 1` 
     8TID=`/sbin/ip addr show dev ${IFACE} | grep -w ${IFACE}: | tr -s ' ' | cut -d : -f 1` 
    99 
    1010if [ "${GATEWAY}" = "down" ]; then 
     
    1515    /sbin/ip rule del table ${TID} priority ${TID} 
    1616    /sbin/ip route flush cache 
    17     echo "remove routing table and policy for ${IF}" 
     17    echo "remove routing table and policy for ${IFACE}" 
    1818    exit 
    1919fi 
     
    2121 
    2222# get IP address, network mask, default gateway info 
    23 IPADDR=`/sbin/ip addr show dev ${IF} | grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1` 
    24 NETWORK=`/sbin/ip route show dev ${IF} | grep -w ${IPADDR} | cut -d ' ' -f 1` 
     23IPADDR=`/sbin/ip addr show dev ${IFACE} | grep -w inet | tr -s ' ' | cut -d ' ' -f 3 | cut -d / -f 1` 
     24NETWORK=`/sbin/ip route show dev ${IFACE} | grep -w ${IPADDR} | tr -s ' ' | cut -d ' ' -f 1` 
    2525 
    2626if [ -z "${GATEWAY}" ]; then 
    27     GATEWAY=`/sbin/ip route show dev ${IF} | grep -w default | cut -d ' ' -f 3` 
     27    GATEWAY=`/sbin/ip route show dev ${IFACE} | grep -w default | tr -s ' ' | cut -d ' ' -f 3` 
    2828fi 
    2929if [ -z "${GATEWAY}" ]; then 
    30     GATEWAY=`/sbin/ip route | grep -w default | cut -d ' ' -f 3` 
     30    GATEWAY=`/sbin/ip route | grep -w default | tr -s ' ' | cut -d ' ' -f 3` 
    3131    # this may add wrong default route especially on RHEL 
    3232fi 
     
    3434 
    3535# set routing table 
    36 /sbin/ip route add ${NETWORK} dev ${IF} table ${TID} 
    37 /sbin/ip route add default via ${GATEWAY} dev ${IF} table ${TID} 
     36/sbin/ip route add ${NETWORK} dev ${IFACE} table ${TID} 
     37/sbin/ip route add default via ${GATEWAY} dev ${IFACE} table ${TID} 
    3838 
    3939# set routing policy 
     
    4141 
    4242/sbin/ip route flush cache 
    43 echo "add routing table and policy for ${IF} on table ${TID}" 
     43echo "add routing table and policy for ${IFACE} on table ${TID}" 
  • trunk/iproute/setroute.sh

    r10 r14  
    1616GATEWAY=$1 
    1717 
    18 TID=`/sbin/ip addr show dev ${IFACE} | grep -w ${IFACE}: | cut -d : -f 1` 
     18TID=`/sbin/ip addr show dev ${IFACE} | grep -w ${IFACE}: | tr -s ' ' | cut -d : -f 1` 
    1919 
    2020if [ "${PHASE}" = "post-down" ]; then 
     
    3131 
    3232# get IP address, network mask, default gateway info 
    33 IPADDR=`/sbin/ip addr show dev ${IFACE} | grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1` 
     33IPADDR=`/sbin/ip addr show dev ${IFACE} | grep -w inet | tr -s ' ' | cut -d ' ' -f 3 | cut -d / -f 1` 
    3434if [ -z "${IPADDR}" ]; then 
    3535    # fail to bind IP address to device 
     
    3737    exit 
    3838fi 
    39 NETWORK=`/sbin/ip route show dev ${IFACE} | grep -w ${IPADDR} | cut -d ' ' -f 1` 
     39NETWORK=`/sbin/ip route show dev ${IFACE} | grep -w ${IPADDR} | tr -s ' ' | cut -d ' ' -f 1` 
    4040 
    4141if [ -z "${GATEWAY}" ]; then 
    42     GATEWAY=`/sbin/ip route show dev ${IFACE} | grep -w default | cut -d ' ' -f 3` 
     42    GATEWAY=`/sbin/ip route show dev ${IFACE} | grep -w default | tr -s ' ' | cut -d ' ' -f 3` 
    4343fi 
    4444if [ -z "${GATEWAY}" ]; then 
    45     GATEWAY=`/sbin/ip route | grep -w default | cut -d ' ' -f 3` 
     45    GATEWAY=`/sbin/ip route | grep -w default | tr -s ' ' | cut -d ' ' -f 3` 
    4646    # this may add wrong default route especially on RHEL 
    4747fi 
  • trunk/iptables/setnapt.sh

    r10 r14  
    3131 
    3232if [ -z "${GATEWAYS}" ]; then 
    33     GATEWAYS=`/sbin/ip route show table main | grep -w default | cut -d ' ' -f 5` 
     33    GATEWAYS=`/sbin/ip route show table main | grep -w default | tr -s ' ' | cut -d ' ' -f 5` 
    3434fi 
    3535 
     
    4040    fi 
    4141     
    42     IPADDR=`/sbin/ip addr show dev ${GW} | grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1` 
     42    IPADDR=`/sbin/ip addr show dev ${GW} | grep -w inet | tr -s ' ' | cut -d ' ' -f 3 | cut -d / -f 1` 
    4343    if [ -z "${IPADDR}" ]; then 
    4444        # device doesn't seem to have an IP address 
Note: See TracChangeset for help on using the changeset viewer.