You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.3 KiB

  1. #!/bin/sh
  2. [ -z "$10" ] && echo "Error: should not be started manually" && exit 0
  3. if [ -e /var/run/mwan3track-$1.pid ] ; then
  4. kill $(cat /var/run/mwan3track-$1.pid) &> /dev/null
  5. rm /var/run/mwan3track-$1.pid &> /dev/null
  6. fi
  7. echo "$$" > /var/run/mwan3track-$1.pid
  8. score=$(($7+$8))
  9. track_ips=$(echo $* | cut -d ' ' -f 9-99)
  10. host_up_count=0
  11. lost=0
  12. while true; do
  13. for track_ip in $track_ips; do
  14. ping -I $2 -c $4 -W $5 -s $9 -q $track_ip &> /dev/null
  15. if [ $? -eq 0 ]; then
  16. let host_up_count++
  17. else
  18. let lost++
  19. fi
  20. done
  21. if [ $host_up_count -lt $3 ]; then
  22. let score--
  23. if [ $score -lt $8 ]; then score=0 ; fi
  24. if [ $score -eq $8 ]; then
  25. logger -t mwan3track -p notice "Interface $1 ($2) is offline"
  26. env -i ACTION=ifdown INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface
  27. score=0
  28. fi
  29. else
  30. if [ $score -lt $(($7+$8)) ] && [ $lost -gt 0 ]; then
  31. logger -t mwan3track -p info "Lost $(($lost*$4)) ping(s) on interface $1 ($2)"
  32. fi
  33. let score++
  34. lost=0
  35. if [ $score -gt $8 ]; then score=$(($7+$8)); fi
  36. if [ $score -eq $8 ]; then
  37. logger -t mwan3track -p notice "Interface $1 ($2) is online"
  38. env -i ACTION=ifup INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface
  39. rm /var/run/mwan3track-$1.pid
  40. exit 0
  41. fi
  42. fi
  43. host_up_count=0
  44. sleep $6
  45. done
  46. exit 1