Last active
November 14, 2017 07:47
-
-
Save D4rk4/927bf56698a1f324a84b9fda7c89048e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DATE="$(date '+%Y.%m.%d, %I:%M:%Ss')" | |
# Interface | |
INET_NAME="eth0" | |
PING_CHECK_STATE="/opt/scripts/ping.state" | |
PING_CHECK_REBOOT_LOG="/var/log/ping_check_reboot.log" | |
PING_CHECK_SUCESS_LOG="/var/log/ping_check_sucess.log" | |
PING="$(which ping)" | |
PING_TARGET="8.8.8.8" | |
PING_OPTS="-c 1 -i 1" | |
PING_CHECK_A="$(cat ${PING_CHECK_STATE} | grep 'icmp_seq=1' | awk '{ printf $5 "\n" }')" | |
PING_CHECK_B="icmp_seq=1" | |
function f_ping { | |
# ping -I eth0 -c 1 -i 1 8.8.8.8 > /tmp/ping.log | |
$PING $PING_OPTS $PING_TARGET > $PING_CHECK_STATE | |
} | |
function f_check { | |
if [ "$PING_CHECK_A" == "$PING_CHECK_B" ]; then | |
echo "[$DATE] Uplink is OK" > $PING_CHECK_SUCESS_LOG | |
else | |
echo "[$DATE] Uplink is DOWN" >> $PING_CHECK_REBOOT_LOG | |
sleep 5 | |
/opt/scripts/vtrunk_init.sh | |
fi | |
} | |
# Main | |
f_ping | |
f_check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment