Skip to content

Instantly share code, notes, and snippets.

@myouju
Last active September 28, 2015 08:36
Show Gist options
  • Save myouju/89048363d35b22da936d to your computer and use it in GitHub Desktop.
Save myouju/89048363d35b22da936d to your computer and use it in GitHub Desktop.
sshでログインされたときに何かする
#!/bin/bash
DATE=`date`
CLIENT_IP=`echo ${SSH_CLIENT} | cut -d " " -f 1`
HOST_IP=`curl inet-ip.info 2>/dev/null`
HOST_NAME=`hostname`
msg="${HOST_NAME}(${HOST_IP}) [${DATE}] ${USER}が${CLIENT_IP}から接続しました!!"
## output log
# echo $msg >> /tmp/login.log
## alter to slack
# curl -X POST --data-urlencode 'payload={"channel": "#alert", "username": "bot", "text": "'"${msg}"'", "icon_emoji": ":shit:"}' https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment