Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
- #SCRIPT TO RESTART WIFI ON DISCONNECT
- #
- # v1.0 - first version
- # v1.1 - added ip check at boot and reconnect
- echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Reconnection script started."
- sleep 10
- echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Checking IP..."
- phantomjs /home/sigma/router/getcurrentip.js
- while :
- do
- if ! ifconfig | grep --quiet "192.168.2.200"; then
- echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Not connected, checking if LAN3 network is available..."
- if iwlist wlan0 scan | grep --quiet ""LAN3""; then
- echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Network is available! Restarting WLAN..."
- ifconfig wlan0 down #> /dev/null
- sleep 1
- ifconfig wlan0 up #> /dev/null
- sleep 10
- if ifconfig | grep --quiet "192.168.2.200"; then
- echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Reconnection successful!"
- echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Checking IP..."
- phantomjs /home/sigma/router/getcurrentip.js
- else
- echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Reconnection failed!"
- fi
- else
- echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Network is not available... going to sleep for 20s."
- sleep 20
- fi
- fi
- sleep 10
- done
- @reboot /bin/bash /home/sigma/wifi/reconnect.sh >> /var/log/wifi_reconnect.log 2>&1
- 2016-12-10 02:45:43 Reconnection script started.
- 2016-12-10 02:46:00 Checking IP...
- *** Step #1 - Login
- * Get http://192.168.2.1...
- * Got it, skipping internet connection status checks.
- * Login successful.
- *** Step #2 - Getting current IP address...
- * Current IP address is: xxx
- *** Step #3 - Saving IP address (xxx) ...
- * All done.
- (manual router reboot)
- 2016-12-10 02:46:26 Not connected, checking if LAN3 network is available...
- 2016-12-10 02:46:26 Network is not available... going to sleep for 20s.
- 2016-12-10 02:46:56 Not connected, checking if LAN3 network is available...
- 2016-12-10 02:46:57 Network is not available... going to sleep for 20s.
- 2016-12-10 02:47:27 Not connected, checking if LAN3 network is available...
- 2016-12-10 02:47:28 Network is not available... going to sleep for 20s.
- 2016-12-10 02:47:58 Not connected, checking if LAN3 network is available...
- 2016-12-10 02:47:58 Network is not available... going to sleep for 20s.
- 2016-12-10 02:48:28 Not connected, checking if LAN3 network is available...
- wlan0 Interface doesn't support scanning : Resource temporarily unavailable
- 2016-12-10 02:48:28 Network is not available... going to sleep for 20s.
- root@sigma:/var/log# ps -auxww | grep "reconnect"
- root 474 0.0 0.0 1912 368 ? Ss 02:45 0:00 /bin/sh -c /bin/bash "/home/sigma/wifi/reconnect.sh" >> /var/log/wifi_reconnect.log 2>&1
- root 477 0.0 0.2 4620 2580 ? S 02:45 0:00 /bin/bash /home/sigma/wifi/reconnect.sh
- root 5940 0.0 0.2 4280 2004 pts/1 S+ 02:57 0:00 grep reconnect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement