ifconfigKeepAlive.sh 688 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/sh
  2. if [ "$1" = "" ]; then
  3. echo "USAGE: $0 [INTERFACE]"
  4. exit 0
  5. fi
  6. get_date (){
  7. echo "$(date '+%Y%m%d-%H%M%S')"
  8. }
  9. check_ip (){
  10. ip=$(curl --silent --connect-timeout 1 ifconfig.me)
  11. if [ "$ip" = "" ]; then
  12. last_connection_lost_date=$(cat /tmp/connection_lost_date)
  13. date +"%s" > /tmp/connection_lost_date
  14. current_connection_lost_date=$(cat /tmp/connection_lost_date)
  15. connection_time=$((current_connection_lost_date-last_connection_lost_date))
  16. doas sh /etc/netstart $1
  17. sleep 10
  18. echo "ERROR: $(get_date) - $0 - Connection reset after $connection_time seconds"
  19. fi
  20. }
  21. date +"%s" > /tmp/connection_lost_date
  22. while true
  23. do
  24. check_ip
  25. sleep 10
  26. done