データストリームの正規表現

データストリームの正規表現

私のデータストリームに何かがあるかどうかをテストし、終了コードを実行したいと思います。

以下のデータストリーミングを提供するgammuモニタを使用します。

[root@MYSERVER ~]# gammu monitor
Press Ctrl+C to break...
Entering monitor mode...

Enabling info about incoming SMS    : No error.
Enabling info about incoming CB     : Some functions not available for your system (disabled in config or not written).
Enabling info about calls           : No error.
Enabling info about USSD            : No error.
SIM phonebook        :  42 used,  38 free
Dialled numbers      :   2 used,  28 free
Received numbers     :   0 used,  30 free
Missed numbers       :   0 used,   0 free
Phone phonebook      :  55 used, 945 free
ToDos                :   0 used, 353 free
Calendar             :  27 used, 353 free
Battery level        : 25 percent
Charge state         : battery connected, but not powered from battery
Signal strength      : -83 dBm
Network level        : 100 percent
SIM SMS status       : 0 used, 0 unread, 13 locations
Phone SMS status     : 1 used, 0 unread, 200 locations
Network state        : home network
Network              : 208 10 (SFR, France), LAC 6414, CID 0000AC99

私のBashスクリプトで次のことができると思います。

#!/bin/bash

gammu monitor |
tail -n 1 |
if[[ "$1"=="Press*" ]]
then
  echo "yes"
else
  echo "no"
fi;

たとえば、バッテリーの充電ラインを確認するには、数字が> 50(0番コンセント)、1番コンセントは25番、2番コンセントは25番です。 Atm、最初の行が次に始まるかどうかをテストしたかったのですが、Pressしばしば動作しません!

gammu monitor対象:Nagiosこのスクリプトをプラグインとして使用して正しい値が返されていることを確認し、そうでない場合またはにwarning移動しますcritical

ベストアンサー1

この例では、私が何が起こっているのかについてより明確なアイデアを提供しようとしています。スクリプトを少しだけ遊ぶと、好きな結果が得られます。

#!/bin/bash
obtain_level=$(gammu monitor | awk '/Battery level/{print $4}') 
 if (( obtain_level <= 25 )) 
  then 
    echo "less than 25"
 elif (( obtain_level >= 26 || obtain_level <= 50 )) 
 then 
   echo "between 25 and 50" 
 else 
   echo "good" 
 fi

おすすめ記事