Skip to content

Instantly share code, notes, and snippets.

@lunatilia
Created June 13, 2015 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lunatilia/79aa4aeb57589a54b571 to your computer and use it in GitHub Desktop.
Save lunatilia/79aa4aeb57589a54b571 to your computer and use it in GitHub Desktop.
Raspberry PiでWi-Fi接続が切れたときに自動で再接続させるスクリプト for Raspbian
#!/bin/bash
USSID="<自環境のSSIDを入力>"
IF_FILE="/etc/network/interfaces"
PARAM_GATEWAY=`grep -i gateway ${IF_FILE} | cut -f2 -d' '`
PARAM_ADDR=`grep -i address ${IF_FILE} | cut -f2 -d' '`
ping -c 4 ${PARAM_GATEWAY} > /dev/null 2>&1
flag=$?
if [ $flag -ne 0 ]; then
/sbin/ifconfig wlan0 | grep inet | grep ${PARAM_ADDR} > /dev/null 2>&1
flag=$?
if [ $flag -ne 0 ]; then
/sbin/iwconfig wlan0 | grep ${USSID} > /dev/null 2>&1
flag=$?
if [ $flag -ne 0 ]; then
/etc/ifplugd/ifplugd.action wlan0 up
sleep 30
/usr/sbin/service ntp restart
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment