Skip to content

Instantly share code, notes, and snippets.

@naa0yama
Last active April 8, 2017 00:57
Show Gist options
  • Save naa0yama/d656fd7522ef95a6826ba9b36f05078a to your computer and use it in GitHub Desktop.
Save naa0yama/d656fd7522ef95a6826ba9b36f05078a to your computer and use it in GitHub Desktop.
SSHログインをSlackに通知する。 ref: http://qiita.com/FoxBoxsnet/items/a496e4bf158177e263fc
$ mkdir ~/.ssh/
$ vi ~/.ssh/rc
#!/bin/bash
url="https://hooks.slack.com/services/xxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxx"
readonly USER=`whoami`
readonly HOST=`hostname`
ip=`who | awk '{print $6}' | cut -d '(' -f 2 | sed -e 's/)//g'`
user=`w -hsi | awk '{print $1}'`
day=`lastlog | grep -w "${USER}" | awk '{print $4}'`
month=`lastlog | grep -w "${USER}" | awk '{print $5}'`
date=`lastlog | grep -w "${USER}" | awk '{print $6}'`
time=`lastlog | grep -w "${USER}" | awk '{print $7}'`
payload="payload={
\"attachments\": [
{
\"color\": \"#36a64f\",
\"title\": \"SSH Connection has established.\",
\"fallback\": \"SSH Connection has established.\",
\"fields\": [
{
\"title\": \"HOSTNAME\",
\"value\": \"${HOST}\",
\"short\": true
},
{
\"title\": \"Date / Time\",
\"value\": \"${month} ${date} (${day}) ${time}\",
\"short\": true
},
{
\"title\": \"User Name\",
\"value\": \"${user}\",
\"short\": true
},
{
\"title\": \"from\",
\"value\": \"${ip}\",
\"short\": true
}
]
}
]
}"
curl -m 5 --data-urlencode "${payload}" "${url}" > /dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment