Created
November 12, 2017 09:59
-
-
Save silgon/825ae85807f8aba6e86376efc56d1beb to your computer and use it in GitHub Desktop.
Reconnect Raspberry Pi wifi when no connection appears
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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