Skip to content

Instantly share code, notes, and snippets.

@toripiyo
Created June 3, 2017 08:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toripiyo/d113b4e2638a699865d09f3af383639e to your computer and use it in GitHub Desktop.
Save toripiyo/d113b4e2638a699865d09f3af383639e to your computer and use it in GitHub Desktop.
sshrc file for ssh notification to slack
#!/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