之前寫過 speedtest 測試頻寬
比較麻煩的是,每次都要手動測試,而且沒有留下歷史紀錄,事實上,SpeedTest 有用 python 寫一個 command 的測試
https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest_cli.py
使用 Apache 授權
需要先安裝 python
下載 speedtest 的 command line script
wget -O /root/speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest_cli.py
chmod 755 /root/speedtest-cli
手動執行 command line 測試頻寬
接下來就要發揮 Linux shell script 的 威力,執行 speedtest command line,將結果產出到文字檔,並透過 Apache Web Server 分享【如果有安全上的疑慮,可以加個 ID/password 的保護】,最後再使用 gnuplot 化成圖型,同樣以 Apache Web Server 分享
shell script 如下
#!/bin/bash test -f /root/speedtest-cli || ( wget -O /root/speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest_cli.py ; chmod 755 /root/speedtest-cli ) /root/speedtest-cli > /tmp/$$ DOWNLOAD=$(grep ‘^Download’ /tmp/$$) echo -n “$(date +%H:%M:%S) " >> /var/www/html/bandwidth_history.txt # plot the data rm /tmp/$$ |
安裝 Apache Web Server,並啟動服務
systemctl start httpd
systemctl enable httpd
將 shell script 加入排程
開 Browser 觀察
<html> |
文字形式:
圖型方式呈現:
這樣就能自動執行 speedtest,並且留下文字及圖型的 output,以 Apache Web Server 方式呈現!
感謝分享!