Skip to content

Instantly share code, notes, and snippets.

@shyazusa
Last active February 17, 2017 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shyazusa/15f1c7bbdc5c13a08d4002e6bcdd666e to your computer and use it in GitHub Desktop.
Save shyazusa/15f1c7bbdc5c13a08d4002e6bcdd666e to your computer and use it in GitHub Desktop.
これは `~/.ssh/rc` ファイルです。一人がアクセスしたときはslackにアクセスメッセを。二人以降が同時にアクセスしてきたら重複ログインやで的なメッセージをslackとコンソールに流します。
#!/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