Skip to content

Instantly share code, notes, and snippets.

@rluisr
Last active June 29, 2016 02:50
Show Gist options
  • Save rluisr/ff7c5f9b9882133bfc503c05e7005a0f to your computer and use it in GitHub Desktop.
Save rluisr/ff7c5f9b9882133bfc503c05e7005a0f to your computer and use it in GitHub Desktop.
Notify you through Slack when SSH connection is established.
#!/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