バッシュはPPSを計算します

バッシュはPPSを計算します

インターフェイスでppsを計算できる小さなbashスクリプトを作成しました。着信ppsが必要な制限に達すると、コマンドを実行します。

スクリプトの実行中にエラーが発生します。誰でも助けることができますか?

これはスクリプトです。

#!/bin/bash

INTERVAL="1"  # update interval in seconds
LIMIT="3000" # Limit in KB/S
URL1="http://1.1.1.1/abcd.php"
IFS=( ens3 ) # Interface names

while true
do
        for i in "${IFS[@]}"
        do
            R1=$(cat /sys/class/net/$i/statistics/rx_packets)
            T1=$(cat /sys/class/net/$i/statistics/tx_packets)
            sleep $INTERVAL
            R2=$(cat /sys/class/net/$i/statistics/rx_packets)
            T2=$(cat /sys/class/net/$i/statistics/tx_packets)
            TBPS=$(expr $T2 - $T1)
            RBPS=$(expr $R2 - $R1)

            echo "Incoming $i: $RKBPS pps || Outgoing $i: $TKBPS pps"
            if (( $RKBPS > $LIMIT )); then
                # Incoming Limit Exceeded
                #bash $URL1
                #sleep 10
                curl $URL1
                sleep 320
            fi
        done
done

私が受け取るエラーは次のとおりです。

Incoming ens3:  pps || Outgoing ens3:  pps
./s.sh: line 22: ((: > 3000 : syntax error: operand expected (error token is "> 3000 ")
Incoming ens3:  pps || Outgoing ens3:  pps
./s.sh: line 22: ((: > 3000 : syntax error: operand expected (error token is "> 3000 ")
Incoming ens3:  pps || Outgoing ens3:  pps
./s.sh: line 22: ((: > 3000 : syntax error: operand expected (error token is "> 3000 ")
Incoming ens3:  pps || Outgoing ens3:  pps
./s.sh: line 22: ((: > 3000 : syntax error: operand expected (error token is "> 3000 ")
Incoming ens3:  pps || Outgoing ens3:  pps
./s.sh: line 22: ((: > 3000 : syntax error: operand expected (error token is "> 3000 ")
Incoming ens3:  pps || Outgoing ens3:  pps
./s.sh: line 22: ((: > 3000 : syntax error: operand expected (error token is "> 3000 ")
Incoming ens3:  pps || Outgoing ens3:  pps
./s.sh: line 22: ((: > 3000 : syntax error: operand expected (error token is "> 3000 ")
Incoming ens3:  pps || Outgoing ens3:  pps
./s.sh: line 22: ((: > 3000 : syntax error: operand expected (error token is "> 3000 ")
Incoming ens3:  pps || Outgoing ens3:  pps
./s.sh: line 22: ((: > 3000 : syntax error: operand expected (error token is "> 3000 ")

誰か私を助けてください。ティア

ベストアンサー1

TBPS2つの変数とを設定し、RBPSTKBPSを参照してくださいRKBPS

また、ドアのsleep外側に簡単な説明を追加する必要がありますif。そうしないと、値を超えないと緊密なループに陥るため、CPUが大量に消費されます。

おすすめ記事