Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #!/bin/bash
  2. read -r CURRENT_IFA < $CURRENT_IFA_FILE
  3. NOW=$(date --iso-8601=ns | sed s/,/./)
  4.  
  5. ping -I eth0 -c 1 google.com >> /dev/null
  6.  
  7. if [ $? -eq 0 ]; then
  8. if [[ $CURRENT_IFA != "eth0" ]]; then
  9. # If we're using another interface than ethernet,
  10. # switch back to ethernet
  11. echo "{"event": "switchifa", "to": "eth0", "msg": "Switch to ethernet", "datetime": "$NOW"}"
  12. sudo ifmetric eth0 50
  13. sudo ifmetric eth1 100 >> /dev/null
  14. echo "eth0" > $CURRENT_IFA_FILE
  15. fi
  16. else
  17. if [[ $CURRENT_IFA != "eth1" ]]; then
  18. # If we're not on 4G, switch to it
  19. echo "{"event": "switchifa", "to": "eth1", "msg": "Switch to 4G", "datetime": "$NOW"}"
  20. sudo ifmetric eth1 50 >> /dev/null
  21. sudo ifmetric eth0 100
  22. echo "eth1" > $CURRENT_IFA_FILE
  23. fi
  24. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement