Last active
April 15, 2020 04:06
-
-
Save swallowstalker/fed5d0352db55ae94bb05e3b3292f8b7 to your computer and use it in GitHub Desktop.
Keep alive connection, install this gist on cron every 1 minute
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 | |
# ping process detector. if no running ping process, execute it once | |
# to be called by cron (for checking and re-spawn) every 1 minute | |
# need to specify destination IP for ping first | |
if [[ -z $DEST_IP ]]; then | |
echo "Please set DEST_IP before calling this script" | |
exit 1 | |
fi | |
# detect if there's any running ping process for that IP | |
ping_proc_count=`ps aux | grep "ping $DEST_IP" | wc -l` | |
# if running ping process does not exist, re-execute ping | |
# if there's already running ping process, do nothing (keep it that way) | |
if [[ "$ping_proc_count" == "1" ]]; then | |
echo "Ping is not alive, restarting..." | |
ping $DEST_IP & | |
fi | |
echo "Ping checker finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment