カールを使用してWebページでヘルスチェックを実行する

カールを使用してWebページでヘルスチェックを実行する

特定の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

カールオプションを見てみましたが、成功したときに沈黙し、エラー時にノイズを発生させようとしている状況に適したものが見つかりませんでした。

私が望むことを行うためにカールを取得する方法や考慮すべき他のツールがありますか?

ベストアンサー1

何について-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

おすすめ記事