Skip to content

Instantly share code, notes, and snippets.

@lwille
Created May 7, 2012 11:05
Show Gist options
  • Save lwille/2627263 to your computer and use it in GitHub Desktop.
Save lwille/2627263 to your computer and use it in GitHub Desktop.
Reconnect Script for crappy USB UMTS routers
#!/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