lundi 24 septembre 2018

Bash while do and if with Telegram API

I am trying to monitor a 24/7 stream. For this Iam monitoring the networkspeed of my raspberry.

Network Speed in Kbits:

(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)

The output is in Kbit/s:

    216
    384
    288
    360
    336
    360

Now I want use Telegram API to trigger if the speed will sink below 100 Kbit/s

Telegram Code:

curl -s -X POST 'https://api.telegram.org/<BOT ID>:<API KEY>/sendMessage?chat_id=<ID>&text="Stream has problems"'

For that I need a while do loop and a if condition.

Kind regards, Goeks1

Aucun commentaire:

Enregistrer un commentaire