TringaliLuca

Autoreconnect service for RaspberryPi when connection drops

Jan 5th, 2017
87
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sudo nano /root/autoreconnect.sh
  2. ***
  3. #!/bin/bash
  4. interface='wlan0'
  5. while true ; do
  6. if ifconfig $interface | grep -q "inet addr:" ; then
  7. echo "Network is working"
  8. sleep 60
  9. else
  10. echo "Network connection down! Attempting reconnection."
  11. systemctl restart networking.service
  12. ifup --force $interface
  13. sleep 10
  14. fi
  15. done
  16. *** Ctrl+O Ctrl+X
  17.  
  18. sudo chmod +x /root/autoreconnect.sh
  19.  
  20. sudo nano /lib/systemd/system/autoreconnect.service
  21. ***
  22. [Unit]
  23. Description=Autoreconnect wlan0 on Raspberry
  24. [Service]
  25. ExecStart=/root/autoreconnect.sh
  26. StandardOutput=null
  27. [Install]
  28. WantedBy=multi-user.target
  29. Alias=autoreconnect.service
  30. *** Ctrl+O Ctrl+X
  31.  
  32. sudo systemctl enable autoreconnect.service
  33.  
  34. sudo systemctl start autoreconnect.service
  35.  
  36. systemctl
RAW Paste Data