Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #!/bin/bash
  2. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  3.  
  4. #SCRIPT TO RESTART WIFI ON DISCONNECT
  5. #
  6. # v1.0 - first version
  7. # v1.1 - added ip check at boot and reconnect
  8.  
  9. echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Reconnection script started."
  10. sleep 10
  11.  
  12. echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Checking IP..."
  13. phantomjs /home/sigma/router/getcurrentip.js
  14.  
  15. while :
  16. do
  17. if ! ifconfig | grep --quiet "192.168.2.200"; then
  18. echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Not connected, checking if LAN3 network is available..."
  19. if iwlist wlan0 scan | grep --quiet ""LAN3""; then
  20. echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Network is available! Restarting WLAN..."
  21. ifconfig wlan0 down #> /dev/null
  22. sleep 1
  23. ifconfig wlan0 up #> /dev/null
  24. sleep 10
  25. if ifconfig | grep --quiet "192.168.2.200"; then
  26. echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Reconnection successful!"
  27. echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Checking IP..."
  28. phantomjs /home/sigma/router/getcurrentip.js
  29. else
  30. echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Reconnection failed!"
  31. fi
  32. else
  33. echo `date "+%Y-%m-%d %H:%M:%S" | tr -d 'n'` "Network is not available... going to sleep for 20s."
  34. sleep 20
  35. fi
  36. fi
  37. sleep 10
  38. done
  39.  
  40. @reboot /bin/bash /home/sigma/wifi/reconnect.sh >> /var/log/wifi_reconnect.log 2>&1
  41.  
  42. 2016-12-10 02:45:43 Reconnection script started.
  43. 2016-12-10 02:46:00 Checking IP...
  44. *** Step #1 - Login
  45. * Get http://192.168.2.1...
  46. * Got it, skipping internet connection status checks.
  47. * Login successful.
  48.  
  49. *** Step #2 - Getting current IP address...
  50. * Current IP address is: xxx
  51.  
  52. *** Step #3 - Saving IP address (xxx) ...
  53. * All done.
  54. (manual router reboot)
  55. 2016-12-10 02:46:26 Not connected, checking if LAN3 network is available...
  56. 2016-12-10 02:46:26 Network is not available... going to sleep for 20s.
  57. 2016-12-10 02:46:56 Not connected, checking if LAN3 network is available...
  58. 2016-12-10 02:46:57 Network is not available... going to sleep for 20s.
  59. 2016-12-10 02:47:27 Not connected, checking if LAN3 network is available...
  60. 2016-12-10 02:47:28 Network is not available... going to sleep for 20s.
  61. 2016-12-10 02:47:58 Not connected, checking if LAN3 network is available...
  62. 2016-12-10 02:47:58 Network is not available... going to sleep for 20s.
  63. 2016-12-10 02:48:28 Not connected, checking if LAN3 network is available...
  64. wlan0 Interface doesn't support scanning : Resource temporarily unavailable
  65.  
  66. 2016-12-10 02:48:28 Network is not available... going to sleep for 20s.
  67.  
  68. root@sigma:/var/log# ps -auxww | grep "reconnect"
  69. 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
  70. root 477 0.0 0.2 4620 2580 ? S 02:45 0:00 /bin/bash /home/sigma/wifi/reconnect.sh
  71. 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