Last active
April 8, 2017 00:57
-
-
Save naa0yama/d656fd7522ef95a6826ba9b36f05078a to your computer and use it in GitHub Desktop.
SSHログインをSlackに通知する。 ref: http://qiita.com/FoxBoxsnet/items/a496e4bf158177e263fc
This file contains 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
$ mkdir ~/.ssh/ | |
$ vi ~/.ssh/rc |
This file contains 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 | |
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