#!/bin/bash
cd /opt/home/admin

touch speedlog.txt
cat speedlog.txt >> hspeedlog.txt
touch hspeedlog.txt
cat hspeedlog.txt | grep -v " 0.00" | awk ' !x[$1]++ '  > hspeedlog1.txt;mv hspeedlog1.txt hspeedlog.txt

killall startcf.sh
killall cf.sh
p=`ps | grep cf.sh | grep -v grep`
while [ ! "$p"x = x ];
do
    sleep 1;
    p=`ps | grep cf.sh | grep -v grep`
done

speed()
{
/etc/storage/cf.sh -e -k -i
sleep 10
p=`ps | grep cf.sh | grep -v grep`
while [ ! "$p"x = x ];
do
    sleep 60;
    p="$(ps | grep cf.sh | grep -v grep;sleep 1)$(ps | grep cf.sh | grep -v grep;sleep 1)$(ps | grep cf.sh | grep -v grep)"
done
}

#只测亚洲的
p_speed_filter='| grep "HKG\\\|NRT\\\|KIX\\\|TPE\\\|ICN\\\|SIN"'
f=/etc/storage/cf.sh && sed -i "s/^p_speed_filter.*/p_speed_filter='$p_speed_filter'/g" $f

logline=1
speedlogline=0
rm speedlog.txt
while [ $logline -gt $speedlogline ]
do
    speed
    sleep 10
    logline=$(eval "cat log.txt $(echo "$p_speed_filter" | sed 's/\\\\*/\\/g')" | wc -l)
    speedlogline=`cat speedlog.txt | grep "\." | wc -l`
done

##恢复脚本配置
f=/etc/storage/cf.sh && sed -i "s/^p_speed_filter.*/p_speed_filter=''/g" $f

/etc/storage/startcf.sh &
