-
-
Save shyazusa/15f1c7bbdc5c13a08d4002e6bcdd666e to your computer and use it in GitHub Desktop.
これは `~/.ssh/rc` ファイルです。一人がアクセスしたときはslackにアクセスメッセを。二人以降が同時にアクセスしてきたら重複ログインやで的なメッセージをslackとコンソールに流します。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
SLACK_URL='https://hooks.slack.com/services/hoge/fuga' # ここにIncomming WebHooksを | |
SLACK_MES='' | |
let LOGIN_USER=$(echo `w` | sed -e 's/.*\([0-9]\+\) user.*/\1/g') | |
if [ ${LOGIN_USER} -ge 2 ] ; then | |
SLACK_MES="既に誰かがログインしている可能性があります。 現在"${LOGIN_USER}"名がログイン中" | |
echo ${SLACK_MES} | |
fi | |
curl ${SLACK_URL} -X POST --data-urlencode 'payload={"channel": "#log", "username": "ghost-bot", "text": "監視対象へのSSH接続を検出いたしました。 '"${SLACK_MES}"'", "icon_emoji": ":ghost:"}' >/dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment