LoginSignup
0
0

More than 1 year has passed since last update.

複数のドメインが稼働しているかを監視してChatWorkに通知してくれるシェルスクリプトを作成した件

Last updated at Posted at 2022-02-25

概要

SSL証明書を監視する対象ドメイン(400件)が稼働しているかを調べる必要があったのでシェルスクリプトで確認できるようにした

#!/bin/bash

domains=(
  https://example.com/
  https://www.yahoo.co.jp/
)

MAXCOUNT=${#domains[@]}

for v in "${domains[@]}"; do
  count=$((count + 1))
  code=$(curl -m 2 -o /dev/null -s -w %{http_code} $v)
  TITLE="HTTPレスポンスが返ってきたドメイン"

  # ステータスが返ってきているドメインを取得
  [ "$code" -ne 000 ] && MESSAGE+="
    $v"

  # ステータスが1つも返らない場合・監視ドメイン終了するまで実行
  if [ -n "$MESSAGE" -a ${count} == ${MAXCOUNT} ]; then
    echo 'END'
    curl -X POST -H "X-ChatWorkToken: xxxx" -d "body=[info][title] $TITLE [/title] [toall]$MESSAGE [/info]" "https://api.chatwork.com/v2/rooms/xxxx/messages"
    exit
  fi
done

スクリーンショット 2022-02-25 22.14.44.png

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0