Curl
使用 curl 對網頁進行健康檢查
我想通過呼叫特定的 url 對服務進行健康檢查。感覺最簡單的解決方案是每分鐘左右使用 cron 進行檢查。如果出現錯誤,cron 會向我發送電子郵件。
我嘗試為此使用 cUrl,但我無法讓它僅在錯誤時輸出消息。如果我嘗試將輸出定向到 /dev/null,它會列印出進度報告。
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 5559 100 5559 0 0 100k 0 --:--:-- --:--:-- --:--:-- 106k
我嘗試查看 curl 選項,但我找不到任何適合您希望它對成功保持沉默但對錯誤發出噪音的情況。
有沒有辦法讓 curl 做我想做的事,或者我應該看看其他一些工具?
怎麼樣
-sSf
?從手冊頁:-s/--silent Silent or quiet mode. Do not show progress meter or error messages. Makes Curl mute. -S/--show-error When used with -s it makes curl show an error message if it fails. -f/--fail (HTTP) Fail silently (no output at all) on server errors. This is mostly done to better enable scripts etc to better deal with failed attempts. In normal cases when a HTTP server fails to deliver a document, it returns an HTML document stating so (which often also describes why and more). This flag will prevent curl from outputting that and return error 22. This method is not fail-safe and there are occasions where non-successful response codes will slip through, especially when authentication is involved (response codes 401 and 407).
例如:
curl -sSf http://example.org > /dev/null