Created
June 3, 2017 08:40
-
-
Save toripiyo/d113b4e2638a699865d09f3af383639e to your computer and use it in GitHub Desktop.
sshrc file for ssh notification to 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/bash | |
# [description] | |
# This script will be executed when someone login with ssh daemon | |
# [how to use] | |
# 1. put this file as a /etc/ssh/sshrc | |
# 2. change file permission with "chmod 755 /etc/ssh/sshrc" | |
# Send Slack's alerts room | |
PATH=/usr/bin:/bin:/sbin:/usr/sbin | |
TIME=`date` | |
IP=`who | cut -d'(' -f2 | cut -d')' -f1 | sort | uniq -c | sort -rn` | |
MESSAGE="Someone has logined: ${TIME}\n${IP}" | |
WEBHOOK_URL='https://hooks.slack.com/services/XXXX/XXX/XXX' | |
curl -X POST --data-urlencode 'payload={"channel": "#alerts", "username": "alerts", "text": "'"${MESSAGE}"'", "icon_emoji": ":dog:"}' ${WEBHOOK_URL} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment