version 1.3, 2009/12/17 11:44:47
|
version 1.7, 2010/08/18 11:38:24
|
Line 1
|
Line 1
|
#!/bin/bash |
#!/bin/bash |
|
|
# switchhgate 0.0.3 |
# switchhgate 0.0.4 |
# (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 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\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\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)" |
EMAIL_SUBJECT="Attention: $(hostname -f) Not operating on standard default gateway!" |
EMAIL_SUBJECT="Attention: $(hostname -f) not operating on standard default gateway!" |
echo -e "$EMAIL_BODY" | mail -s "$EMAIL_SUBJECT" "$ALERT_EMAIL" |
echo -e "$EMAIL_BODY" | mail -s "$EMAIL_SUBJECT" "$ALERT_EMAIL" |
if [[ -n "$DEBUG" && "$DEBUG" != "low" ]]; then |
if [[ -n "$DEBUG" && "$DEBUG" != "low" ]]; then |
echo "Alert message sent to $ALERT_EMAIL." |
echo "Alert message sent to $ALERT_EMAIL." |
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 |