
私はhttp cgiコマンドを持っています(http://カメラIP:ポート/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=ユーザー&pwd=パスワード)ブラウザで返される
<CGI_Result>
<result>0</result>
<IOAlarm>0</IOAlarm>
<motionDetectAlarm>1</motionDetectAlarm>
<soundAlarm>0</soundAlarm>
<record>0</record>
<sdState>0</sdState>
<sdFreeSpace>0k</sdFreeSpace>
<sdTotalSpace>0k</sdTotalSpace>
<ntpState>1</ntpState>
<ddnsState>0</ddnsState>
<url>http%3A%2F%2Fgg3460.myfoscam.org%3A22222</url>
<upnpState>0</upnpState>
<isWifiConnected>0</isWifiConnected>
<wifiConnectedAP></wifiConnectedAP>
<infraLedState>1</infraLedState>
</CGI_Result>
motionDetectAlarm が 2 に等しいかどうかを確認し、RESTfull API PUT メソッドを呼び出すスクリプトを作成したいのですが、可能ですか?
私はresfull APIを呼び出すことができますcurl -X PUT -d arg=val -d arg2=val2 localhost:8080
while ループを実行するにはどうすればいいですか? ループを永久に実行したいです。 よろしくお願いします。
答え1
「永久に」ループし、Web ページを取得して正確な HTML コードを探します。grep -q
特定のタグと値が存在する場合は「成功」で終了し、次のcurl
実行が可能になります。
while :
do
wget or curl the CGIProxy script | grep -q '<motionDetectAlarm>2</motionDetectAlarm>' &&
curl -X PUT -d arg=val -d arg2=val2 localhost:8080
done