check_network.sh 650 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/bash
  2. # 网络自检任务
  3. ip="10.8.0.1"
  4. source /etc/profile
  5. date="`date '+%Y-%m-%d %H:%M:%S'`"
  6. lost_rate=`ping -c 8 -w 8 $ip | grep 'packet loss' \
  7. | awk -F'packet loss' '{ print $1 }' \
  8. | awk '{ print $NF }' | sed 's/%//g'`
  9. if [ $lost_rate -eq 0 ]
  10. then
  11. echo "network ok"
  12. elif [ $lost_rate -le 100 ]
  13. then
  14. echo "network error"
  15. echo "123456" | sudo -S killall openvpn
  16. if [ ! -d "/opt/datas/log/network" ]; then
  17. mkdir -p /opt/datas/log/network
  18. fi
  19. echo "network_error $date $ip" >>/opt/datas/log/network/network_error.log
  20. echo "123456" | sudo -S service network-manager restart
  21. sleep 4
  22. cd /opt/GSD/network/
  23. ./start_openvpn.sh
  24. fi