Skip to content

Instantly share code, notes, and snippets.

@ryesalvador
Created August 4, 2015 07:44
Show Gist options
  • Save ryesalvador/d15386007a58d5069228 to your computer and use it in GitHub Desktop.
Save ryesalvador/d15386007a58d5069228 to your computer and use it in GitHub Desktop.
A bash script that keeps my Raspberry Pi wireless internet connection open
#!/bin/bash
# Script from hackhappy.org
while [ true ]
do
sleep 20
wget -q --spider http://www.google.com/
if [ "$?" != 0 ]; then
sudo ifdown wlan0 && sudo ifup wlan0
fi
done
#! /bin/sh
# /etc/init.d/wifi
### BEGIN INIT INFO
# Provides: wifi
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple script to start a program at boot
# Description: A simple script from www.stuffaboutcode.com which will start / stop a program a boot / shutdown.
### END INIT INFO
# If you want a command to always run, put it here
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting wifi connection"
# run application you want to start
/home/pi/scripts/hackhappy &
;;
stop)
echo "Stopping wifi connection"
# kill application you want to stop
killall hackhappy
;;
*)
echo "Usage: /home/pi/scripts/hackhappy {start|stop}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment