#10:06 2020.04.07
##############################
#REF: https://williamyaps.github.io/wlmjavascript/servercli.html
now1="$(date +'%Y.%m.%d_%H.%M.%S.%3N')"
CITY="Hanoi"
##############################
#_________[SpeedTest_Script]:BEGIN
RESULT_FLD="/opt/temp"
mkdir -p $RESULT_FLD
mkdir -p /opt/script/;cd /opt/script/
#wget https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
#chmod +x speedtest.py
/opt/script/speedtest.py --list > $RESULT_FLD/speedtest-server-list-all.txt
cat $RESULT_FLD/speedtest-server-list-all.txt | grep "$CITY" | awk '{gsub(")",""); print $1}' > $RESULT_FLD/$CITY-isp-full-name.txt
cd $RESULT_FLD
while read LINE; \
do /opt/script/speedtest.py --server "$LINE"; \
done < $RESULT_FLD/$CITY-isp-full-name.txt > $RESULT_FLD/$CITY-isp-result-$now1.txt
#_________[SpeedTest_Script]:END
#______________________DELETE_OLD_DATA:BEGIN
# SERVER_NAME=$(hostname)
# mkdir -p /opt/bk/$SERVER_NAME/
# cd /opt/bk/$SERVER_NAME/
NumberOfFileWantToKeep=3
#Giu lai [3] file moi nhat trong thu muc [$FOLDER_DST]:
#XOA FILE:
#/bin/rm -rf `ls -t "result*.txt" | awk 'NR>3'`
/bin/rm -rf `ls -t *.txt | awk 'NR>3'`
#XOA FOLDER:
/bin/rm -rf `ls -td */ | awk 'NR>3'`
#______________________DELETE_OLD_DATA:END
#THE_END