Skip to content

Instantly share code, notes, and snippets.

@riipandi
Last active July 28, 2018 08:25
Show Gist options
  • Save riipandi/ccb11a74e3c70edeeacf620c69aaf54d to your computer and use it in GitHub Desktop.
Save riipandi/ccb11a74e3c70edeeacf620c69aaf54d to your computer and use it in GitHub Desktop.
Telegram Bot
#!/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