-
-
Save rluisr/ff7c5f9b9882133bfc503c05e7005a0f to your computer and use it in GitHub Desktop.
Notify you through Slack when SSH connection is established.
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="<web hook url>" | |
readonly USER=`whoami` | |
readonly HOST=`hostname` | |
ip=`lastlog | grep -w "${USER}" | awk '{print $3}'` | |
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\": \"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