Skip to content

Instantly share code, notes, and snippets.

@silgon
Created November 12, 2017 09:59
Show Gist options
  • Save silgon/825ae85807f8aba6e86376efc56d1beb to your computer and use it in GitHub Desktop.
Save silgon/825ae85807f8aba6e86376efc56d1beb to your computer and use it in GitHub Desktop.
Reconnect Raspberry Pi wifi when no connection appears
#! /bin/bash
# This code verify that the computer has an ip. When this is not true
# Cron command
# */5 * * * * /my/path/wifi_reconnect
# ip addr show wlan0 |awk -F ":" '/inet addr/{split($2,a," ");print a[1]}'
IP=$(ifconfig wlan0 | awk '$1 == "inet" {print $2}')
if [ -z $IP ]; then
# wait for 10 seconds and ask again for your ip
sleep 10
IP=$(ifconfig wlan0 | awk '$1 == "inet" {print $2}')
if [ -z $IP ]; then
echo Wifi Restarted at `date` >> /tmp/wifi_stats
ifconfig wlan0 down && ifconfig wlan0 up
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment