Skip to content

Instantly share code, notes, and snippets.

@swallowstalker
Last active April 15, 2020 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swallowstalker/fed5d0352db55ae94bb05e3b3292f8b7 to your computer and use it in GitHub Desktop.
Save swallowstalker/fed5d0352db55ae94bb05e3b3292f8b7 to your computer and use it in GitHub Desktop.
Keep alive connection, install this gist on cron every 1 minute
#!/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