Linux

通过ping包延迟执行任务

#!/bin/sh
pingavg="0"
usehk="1"
limitping=120
dst="目标地址"

systemctl stop v2ray
cp -rf /etc/v2ray/config.hk /etc/v2ray/config.json
systemctl start v2ray

while true; do
    pingavg=$(ping ${dst} -c 10 | grep '^rtt' | awk -F '/' '{print $5F}' | awk '{print int($0)}')
    echo "${pingavg}"
    if [ "$pingavg" -gt "$limitping" ]; then
        echo "HKping包延时超过${limitping}"
        if [ "${usehk}" != "0" ]; then
            systemctl stop v2ray
            cp -rf /etc/v2ray/config.bak /etc/v2ray/config.json
            systemctl start v2ray
            usehk="0"
            echo "切换美服配置"
        fi
    else
        if [ "${usehk}" != "1" ]; then
            systemctl stop v2ray
            cp -rf /etc/v2ray/config.hk /etc/v2ray/config.json
            systemctl start v2ray
            usehk="1"
            echo "切换HK配置"
        fi
    fi
 
    sleep 12

done

留言