Last active
July 28, 2018 08:25
-
-
Save riipandi/ccb11a74e3c70edeeacf620c69aaf54d to your computer and use it in GitHub Desktop.
Telegram Bot
This file contains hidden or 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
#!/usr/bin/env bash | |
# Import credentials form config file | |
. /etc/tg_ssh_notif.conf | |
URL="https://api.telegram.org/bot${KEY}/sendMessage" | |
DATE="$(date "+%d %b %Y %H:%M")" | |
if [ -n "$SSH_CLIENT" ]; then | |
CLIENT_IP=$(echo $SSH_CLIENT | awk '{print $1}') | |
SRV_HOSTNAME=$(hostname -f) | |
SRV_IP=$(hostname -I | awk '{print $1}') | |
IPINFO="https://ipinfo.io/${CLIENT_IP}" | |
TEXT="Connection from *${CLIENT_IP}* as ${USER} on *${SRV_HOSTNAME}* (*${SRV_IP}*) | |
Date: ${DATE} | |
More informations: [${IPINFO}](${IPINFO})" | |
curl -s -d "chat_id=${USERID}&text=${TEXT}&disable_web_page_preview=true&parse_mode=markdown" $URL > /dev/null | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment