Skip to content

Instantly share code, notes, and snippets.

@jbonney jbonney/crontab
Last active Aug 29, 2015

Embed
What would you like to do?
Script to check the internet connection of a kiosk and reload the active page in case the connection drops and then comes back online. Sources: -http://alexba.in/blog/2015/01/14/automatically-reconnecting-wifi-on-a-raspberrypi/ - http://raspberrypi.stackexchange.com/questions/6981/auto-refresh-for-midori - http://www.lynsayshepherd.com/blog/2014…
*/2 * * * * DISPLAY=:0 sh /usr/local/bin/wifi_reloader.sh
#!/bin/bash
# The IP for the server you wish to ping (8.8.8.8 is a public Google DNS server)
# SERVER=8.8.8.8
# Only send two pings, sending output to /dev/null
# ping -c2 ${SERVER} > /dev/null
# Using alternative method to pinging to check if the page exists
wget -q --spider http://www.google.com
# If the return code from ping / wget ($?) is not 0 (meaning there was an error)
if [ $? != 0 ]
then
# Exit full screen in case of error
xdotool search --onlyvisible "Chromium" windowactivate --sync key F11
# Restart the wireless interface
sudo ifdown --force wlan0
sudo ifup wlan0
# Sleep for 45 seconds to give a chance to the network adapter to get an IP
sleep 45s
# Reload the active page (Google Analytics)
xdotool search --onlyvisible "Chromium" windowactivate --sync key F5
# Restore full screen once connection is established
xdotool search --onlyvisible "Chromium" windowactivate --sync key F11
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.