Created
May 7, 2012 11:05
-
-
Save lwille/2627263 to your computer and use it in GitHub Desktop.
Reconnect Script for crappy USB UMTS routers
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/sh | |
# Reconnect Script for crappy USB UMTS routers | |
# Author: Leonhardt Wille <github.com/lwille> | |
host="www.google.de" | |
app="<Application Name>" | |
ping="/sbin/ping" | |
retry_after=1 | |
check_after=5 | |
function execCommand { | |
echo "executing command $app" | |
open -a "$app" | |
} | |
function tryPing { | |
local status='DISCONNECTED' | |
$ping -q -c1 $host &> /dev/null | |
if [ "$?" == 0 ]; then | |
status='CONNECTED' | |
fi | |
echo "$status" | |
} | |
while [ 1 ] | |
do | |
status=$(tryPing) | |
if [ "$status" != 'CONNECTED' ]; then | |
echo "not connected, retrying after $retry_after seconds" | |
echo $(execCommand) | |
sleep $retry_after | |
else | |
echo "CONNECTED, checking after $check_after seconds" | |
sleep $check_after | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment