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