Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

shellでslackにログを残す

Posted at

事前準備

slackのアプリケーションからIncomming Webhooksを作って Webhook URL を取得

コード

today=$(date "+%Y%m%d")
month=$(date "+%Y%m")
slack_webhook_url="https://hooks.slack.com/services/*******/*******/*****************"
function slack_info () {
    title=${1}
    text=${2}
    PAYLOAD=`cat << EOS
        payload={
            "username": "sushi",
            "attachments": [{
                "color": "#00FF00",
                "title": "[INFO] ${today} ${title}",
                "text": "${text}"
            }],
            "icon_emoji": ":sushi:"
        }
EOS`

    curl -X POST --data-urlencode "${PAYLOAD}" ${slack_webhook_url}
}
function slack_error () {
    title=${1}
    text=${2}
    PAYLOAD=`cat << EOS
        payload={
            "username": "sushi",
            "attachments": [{
                "color": "#D00000",
                "title": "[ERROR] ${today} ${title}",
                "text": "${text}"
            }],
            "icon_emoji": ":sushi:"
        }
EOS`

    curl -X POST --data-urlencode "${PAYLOAD}" ${slack_webhook_url}
}
0
2
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

Qiita Advent Calendar is held!

Qiita Advent Calendar is an article posting event where you post articles by filling a calendar 🎅

Some calendars come with gifts and some gifts are drawn from all calendars 👀

Please tie the article to your calendar and let's enjoy Christmas together!

0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?