Skip to content

Instantly share code, notes, and snippets.

@sjmf
Created January 25, 2016 10:55
Show Gist options
  • Save sjmf/2e02fc95ca32e46a7f9a to your computer and use it in GitHub Desktop.
Save sjmf/2e02fc95ca32e46a7f9a to your computer and use it in GitHub Desktop.
Aggressive Wifi-reconnect script
#!/bin/bash
cd "$(dirname "$0")"
# Set up 3g usb dongle ZTE WCDMA Technologies MSM MF110
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root"; exit 1;
fi
# Create script in /opt/
mkdir -p /opt/wifi/
cat <<< '#!/bin/bash
if ! ping -c1 8.8.8.8; then
ifdown --force wlan0 &&
ifup --force wlan0 &&
echo Wifi reset on: `date`
else
echo Wifi is up: `date`
fi
' >/opt/wifi/wifi.sh
chmod +x /opt/wifi/wifi.sh
# Create entry in crontab to run script
crontab -l > mycron
echo "* * * * * bash /opt/tunnel/wifi.sh > /var/log/wifi.log 2>&1" >> mycron
crontab mycron
rm mycron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment