You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
840 B
Bash

#!/bin/bash
local USERID="<Enter_the_user_id_of_the_recipient>"
local KEY="<The_key_of_your_telegram_bot>"
local TIMEOUT="10"
local URL="https://api.telegram.org/bot$KEY/sendMessage"
local DATE_EXEC="$(date "+%d %b %Y %H:%M")" #Collect date & time.
if [ -n "$SSH_CLIENT" ] && [ -z "$TMUX" ]; then #Trigger
IP=$(echo $SSH_CLIENT | awk '{print $1}') #Get Client IP address.
PORT=$(echo $SSH_CLIENT | awk '{print $3}') #Get SSH port
HOSTNAME=$(hostname -f) #Get hostname
IPADDR=$(hostname -I | awk '{print $1}')
TEXT="$DATE_EXEC: ${USER} logged in to $HOSTNAME ($IPADDR) from $IP - $(curl https://ipinfo.io/$IP -s | jq -r '.org + " - " + .city + ", " + .region + ", " + .country') port $PORT"
curl -s --max-time $TIMEOUT -d "chat_id=$USERID&disable_web_page_preview=1&text=$TEXT" $URL > /dev/null
rm $TMPFILE #clean up after
fi