Diff for /badi/public_scripts/switchgate/switchgate between versions 1.4 and 1.8

version 1.4, 2009/12/17 11:55:02 version 1.8, 2017/03/28 21:44:24
Line 1 Line 1
 #!/bin/bash  #!/bin/bash
   
 # switchhgate 0.0.3  # switchhgate 0.0.5
 # (c) 2005 under GPL by Adrian Zaugg  # (c) 2005-2010 under GPL by Adrian Zaugg
   
 # switchgate pings a set of hosts to determine the state of the internet connectivity. If  # switchgate pings a set of hosts to determine the state of the internet connectivity. If
 # the connection is down, it can change the default gateway to an alternative gateway.  # the connection is down, it can change the default gateway to an alternative gateway.
Line 59  function readgwlist { Line 59  function readgwlist {
                 fi                  fi
   
                 allgates=`grep -ve "^[  ]*[\#]\+.*$" "$GATEWAYS_FILE" | xargs`                  allgates=`grep -ve "^[  ]*[\#]\+.*$" "$GATEWAYS_FILE" | xargs`
                   alldhcpgates=""
                 for gate in $allgates; do                  for gate in $allgates; do
                         if [[ $(echo "$gate" | grep -c -e "^[:space:]*dhcp\..*$") -eq 1 && \                          if [[ $(echo "$gate" | grep -c -e "^[[:space:]]*dhcp\..*$") -eq 1 && \
                               -f "$CONFIG_PATH/$gate" ]]; then                                -f "$DHCP_TMP_DIR/$gate" ]]; then
                                 # Read dhcp supplied gate for a specific interface                                  # Read dhcp supplied gate for a specific interface
                                 alldhcpgates=`grep -e "^[^\#].*$" "$CONFIG_PATH/$gate" | xargs`                                  alldhcpgates="$alldhcpgates `grep -e "^[^\#].*$" "$DHCP_TMP_DIR/$gate" | xargs`"
                         elif [[ $(echo "$gate" | grep -c -e "^[:space:]*dhcp[:space:]*$") -eq 1 ]]; then                          elif [[ $(echo "$gate" | grep -c -e "^[[:space:]]*dhcp[[:space:]]*$") -eq 1 ]]; then
                                 # Read all dhcp files                                  # Read all dhcp files
                                 alldhcpgates=""                                  for dhcpfile in $(echo -n $(ls -1 $DHCP_TMP_DIR/dhcp* 2>/dev/null)); do
                                 for dhcpfile in $(echo -n $(ls -1 $DHCP_TMP_DIR/dhcp* 2>/dev/null)); do   
                                         alldhcpgates="$alldhcpgates `grep -e "^[^\#].*$" "$dhcpfile" | xargs`"                                          alldhcpgates="$alldhcpgates `grep -e "^[^\#].*$" "$dhcpfile" | xargs`"
                                 done                                  done
                         else                          else
Line 353  fi Line 353  fi
   
 # send an eMail if the connection is down or limited  # send an eMail if the connection is down or limited
 if [ -z "$UP" ]; then  if [ -z "$UP" ]; then
         EMAIL_BODY="Switchgate on $(hostname -f) reports: No connection!\n\nTime:\t\t$(date)\nGateway:\t$CURRENTGW ($CURRENTGW_ID)"          if [ -z "$NEWGW" ]; then
         EMAIL_SUBJECT="Attention: $(hostname -f) has no connection!"                  EMAIL_BODY="Switchgate on $(hostname -f) reports: No connection!\n\nTime:\t\t$(date)\nGateway:\t$CURRENTGW ($CURRENTGW_ID)"
         echo -e "$EMAIL_BODY" | mail -s "$EMAIL_SUBJECT" "$ALERT_EMAIL"                  EMAIL_SUBJECT="Attention: $(hostname -f) has no connection!"
         if [[ -n "$DEBUG" && "$DEBUG" != "low" ]]; then                  echo -e "$EMAIL_BODY" | mail -s "$EMAIL_SUBJECT" "$ALERT_EMAIL"
                 echo "Alert message sent to $ALERT_EMAIL."                  if [[ -n "$DEBUG" && "$DEBUG" != "low" ]]; then
                           echo "Alert message sent to $ALERT_EMAIL."
                   fi
         fi          fi
 elif [ "$CURRENTGW_ID" != 0 ]; then  elif [ "$CURRENTGW_ID" != 0 ]; then
         EMAIL_BODY="Switchgate on $(hostname -f) reports: Not operating on standard default gateway!\n\nTime:\t\t$(date)\nGateway:\t$CURRENTGW ($CURRENTGW_ID)"          EMAIL_BODY="Switchgate on $(hostname -f) reports: Not operating on standard default gateway!\n\nTime:\t\t$(date)\nGateway:\t$CURRENTGW ($CURRENTGW_ID)"
Line 368  elif [ "$CURRENTGW_ID" != 0 ]; then Line 370  elif [ "$CURRENTGW_ID" != 0 ]; then
         fi          fi
 fi  fi
   
 if [ "$DEBUG" = "low" ]; then  if [ "$DEBUG" = "low" -o "$DEBUG" = "choke" ]; then
    echo          if [ -n "$UP" ]; then
    echo "Default Gateway: $CURRENTGW ($CURRENTGW_ID)"             echo
    echo             echo "Current Default Gateway: $CURRENTGW ($CURRENTGW_ID)"
              echo
           else
              echo
              echo "No connection."
              echo
           fi
 fi  fi
 exit 0  exit 0

Removed from v.1.4  
changed lines
  Added in v.1.8


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