Diff for /badi/public_scripts/switchgate/switchgate between versions 1.2 and 1.3

version 1.2, 2009/12/17 11:16:34 version 1.3, 2009/12/17 11:44:47
Line 28  HOSTSET_FILE="$CONFIG_PATH/hostset" Line 28  HOSTSET_FILE="$CONFIG_PATH/hostset"
 GATEWAYS_FILE="$CONFIG_PATH/gateways"  GATEWAYS_FILE="$CONFIG_PATH/gateways"
   
 # path to fping  # path to fping
 PING=/usr/sbin/fping  PING=/usr/bin/fping
   
 # answer of fping to reachable hosts  # answer of fping to reachable hosts
 ALIVE_ANSWER="is alive"  ALIVE_ANSWER="is alive"
Line 85  function readgwlist { Line 85  function readgwlist {
                         unset alldhcpgates                          unset alldhcpgates
                 done                  done
         fi          fi
           
         if [ "$number_of_gws" -eq 0 ]; then          if [ "$number_of_gws" -eq 0 ]; then
                 echo "No gateways configured. Please edit $GATEWAYS_FILE."                  echo "No gateways configured. Please edit $GATEWAYS_FILE."
                 exit 1                  exit 1
Line 121  function checkconnection { Line 121  function checkconnection {
    if [ -n "$DEBUG" ]; then     if [ -n "$DEBUG" ]; then
       if [ -n "$UP" ]; then        if [ -n "$UP" ]; then
          echo "The connection is up."           echo "The connection is up."
       else         else
          echo "The connection is down."           echo "The connection is down."
       fi        fi
    fi     fi
Line 134  function checkgw { Line 134  function checkgw {
          echo "$NEWGW is reachable."           echo "$NEWGW is reachable."
       fi        fi
     else      else
       if [ -n "$DEBUG" ]; then         if [ -n "$DEBUG" ]; then
           echo "$NEWGW is not reachable."            echo "$NEWGW is not reachable."
       fi        fi
       NEWGW=""        NEWGW=""
Line 148  function getcurrentgw { Line 148  function getcurrentgw {
       exit 1        exit 1
    else     else
       iproute_default_gw_txt="$(echo "$iproute_default_gw_txt" | grep "default via")"        iproute_default_gw_txt="$(echo "$iproute_default_gw_txt" | grep "default via")"
    fi       fi
    if [ -z "$iproute_default_gw_txt" ]; then     if [ -z "$iproute_default_gw_txt" ]; then
       # no default gateway currently set, set to the highest index, to land on GW0        # no default gateway currently set, set to the highest index, to land on GW0
       CURRENTGW_ID=0        CURRENTGW_ID=0
Line 157  function getcurrentgw { Line 157  function getcurrentgw {
       echo "No default gateway currently set. Setting it now to $CURRENTGW."        echo "No default gateway currently set. Setting it now to $CURRENTGW."
       ip route add default via $CURRENTGW        ip route add default via $CURRENTGW
    else     else
       CURRENTGW=`echo $iproute_default_gw_txt | sed "s/^default via \(\([0-9]\+\.\?\)\{4\}\).*\$/\1/"`         CURRENTGW=`echo $iproute_default_gw_txt | sed "s/^default via \(\([0-9]\+\.\?\)\{4\}\).*\$/\1/"`
       CURRENTGW_DEV=`echo $iproute_default_gw_txt | sed "s/^default via .* dev \(eth[0-9]\+\).*\$/\1/"`         CURRENTGW_DEV=`echo $iproute_default_gw_txt | sed "s/^default via .* dev \(eth[0-9]\+\).*\$/\1/"`
    fi     fi
   
    # get index of current gateway     # get index of current gateway
Line 232  function switchgw { Line 232  function switchgw {
    if [ -n "$NEWGW" ]; then     if [ -n "$NEWGW" ]; then
       if [ "$DEBUG" = "low" ]; then        if [ "$DEBUG" = "low" ]; then
          echo -n "Switching default gateway now to $NEWGW ($NEWGW_ID)..."           echo -n "Switching default gateway now to $NEWGW ($NEWGW_ID)..."
       fi         fi
         
       iproute_msg="$(ip route change default via $NEWGW 2>&1 )"        iproute_msg="$(ip route change default via $NEWGW 2>&1 )"
       iproute_exit=$?        iproute_exit=$?
   
Line 241  function switchgw { Line 241  function switchgw {
       sleep 1        sleep 1
       GARBAGE=`$PING -q -c 5 -t100 -p50 -A -f $HOSTSET_FILE 2> /dev/null`        GARBAGE=`$PING -q -c 5 -t100 -p50 -A -f $HOSTSET_FILE 2> /dev/null`
       sleep 1        sleep 1
         
       if [ "$DEBUG" = "low" ]; then        if [ "$DEBUG" = "low" ]; then
          echo "done."           echo "done."
       fi        fi
Line 291  if [ "$1" = "-d" ]; then Line 291  if [ "$1" = "-d" ]; then
         fi           fi 
 fi  fi
   
   # Check fping existence
   if [ ! -x "$PING" ]; then
           echo -e "Error: Ping program not executable or not found at $PING.\nPlease configure the full path in $0."
           exit 1
   fi
   
 # Get all gateways, we can forward traffic  # Get all gateways, we can forward traffic
 readgwlist  readgwlist
   
Line 321  if [ -z "$UP" ]; then Line 327  if [ -z "$UP" ]; then
    checkgw     checkgw
    if [ -z "$NEWGW" ]; then     if [ -z "$NEWGW" ]; then
       echo "Gateway $CURRENTGW is down."        echo "Gateway $CURRENTGW is down."
    else      else
       echo "No connection through gateway $CURRENTGW."         echo "No connection through gateway $CURRENTGW." 
    fi     fi
     
    NEWGW_ID=$CURRENTGW_ID     NEWGW_ID=$CURRENTGW_ID
    switchgw     switchgw
      
 else  else
    # If the current gateway is not the standard default gateway, try if the connection      # If the current gateway is not the standard default gateway, try if the connection 
    # through the standard default gateway is back     # through the standard default gateway is back

Removed from v.1.2  
changed lines
  Added in v.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>