
我有一個 http cgi 指令(http://cameraIP:port/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 apicurl -X PUT -d arg=val -d arg2=val2 localhost:8080
我怎樣才能做 while 迴圈?我希望循環永遠運行。謝謝。
答案1
「永遠」循環,拉出網頁並尋找確切的 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