Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- read -r CURRENT_IFA < $CURRENT_IFA_FILE
- NOW=$(date --iso-8601=ns | sed s/,/./)
- ping -I eth0 -c 1 google.com >> /dev/null
- if [ $? -eq 0 ]; then
- if [[ $CURRENT_IFA != "eth0" ]]; then
- # If we're using another interface than ethernet,
- # switch back to ethernet
- echo "{"event": "switchifa", "to": "eth0", "msg": "Switch to ethernet", "datetime": "$NOW"}"
- sudo ifmetric eth0 50
- sudo ifmetric eth1 100 >> /dev/null
- echo "eth0" > $CURRENT_IFA_FILE
- fi
- else
- if [[ $CURRENT_IFA != "eth1" ]]; then
- # If we're not on 4G, switch to it
- echo "{"event": "switchifa", "to": "eth1", "msg": "Switch to 4G", "datetime": "$NOW"}"
- sudo ifmetric eth1 50 >> /dev/null
- sudo ifmetric eth0 100
- echo "eth1" > $CURRENT_IFA_FILE
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement