13
13

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.

BashからSlackへ投稿する

Posted at

#何すんの?
大前提としてタイトル通りです。主として備忘録です。

#環境

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 15.10
Release:	15.10
Codename:	wily

$ bash --version
GNU bash, バージョン 4.3.42(1)-release (x86_64-pc-linux-gnu)

$ curl -V
curl 7.43.0 (x86_64-pc-linux-gnu) libcurl/7.43.0 GnuTLS/3.3.15 zlib/1.2.8 libidn/1.28 librtmp/2.3
Protocols: (省略)

curlを用います。もし入っていない方はインストールしておいてください。

$ sudo apt-get install -y curl

#Slack投稿スクリプト

postSlack.sh
#!/bin/sh

# postSlack.sh [チャンネル] [Bot名] [本文]

WEBHOOKURL="[Incoming Webhooks URL]"

DATA_PAYLOAD=`cat <<_EOT_
payload={ \
    "channel": "$1", \
    "username": "$2", \
    "text": "$3" \
}
_EOT_`

curl -s -S -X POST --data-urlencode "${DATA_PAYLOAD}" "${WEBHOOKURL}" > /dev/null

#さいごに
現在私が使っている以上では特に問題が起きてませんが、
コレ文字列入れたらセキュリティ的にアレ!みたいなのがあれば教えて頂けると幸いです。

13
13
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
13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?