我正试着监控一条24/7的溪流。为此,我正在监控我的覆盆子的网络速度。
以Kbit为单位的网络速度:
(old="$(</sys/class/net/eth0/statistics/rx_bytes)"; while $(sleep 1); do now=$(</sys/class/net/eth0/statistics/rx_bytes); echo $((($now-$old)/1024)); old=$now; done)输出以Kbit/s为单位:
216
384
288
360
336
360现在,如果速度下降到100 Kbit/s以下,我希望使用Telegram API触发。
电报代码:
TELEGRAM=$(curl -s -X POST 'https://api.telegram.org/<BOT ID>:<API KEY>/sendMessage?chat_id=<ID>&text="Stream has problems"')为此,我需要一个that循环和一个if条件。
好样的,Goeks1
编辑/
$(old="$(</sys/class/net/eth0/statistics/rx_bytes)"; while $(sleep 1); do now=$(</sys/class/net/eth0/statistics/rx_bytes); if (( (now-old)/1024 < 1000 )); then $TELEGRAM ; fi echo $((($now-$old)/1024)); old=$now; done)发布于 2018-09-26 17:36:26
我已经解决了。解决办法如下。
#!/bin/bash
OLD="$(</sys/class/net/eth0/statistics/rx_bytes)"
i=1
while $(sleep 1m); do
NOW=$(</sys/class/net/eth0/statistics/rx_bytes)
if (( (NOW-OLD)/1024 > 100 )) ; then
remainder=$(( i % 3 ))
[ "$remainder" -eq 0 ] && curl -s -X POST 'https://api.telegram.org/<BOT ID>:<API KEY>/sendMessage?chat_id=<ID>&text="Stream has problems"'
i=$(( i + 1 ))
fi
OLD=$NOW
donehttps://stackoverflow.com/questions/52485361
复制相似问题