SSH notification via telegram

Install package

$ sudo yum install -y jq curl 

Create Scripts

$ sudo vi /etc/profile.d/ssh-telegram.sh

add scripts

USERID="123456789"
KEY="1148008123:AAEkdFGqXJPt29-DAQPpPLq0-eeXu5nOjwQ____"
TIMEOUT="10"
URL="https://api.telegram.org/bot$KEY/sendMessage"
DATE_EXEC="$(date "+%d %b %Y %H:%M")"
TMPFILE='/tmp/ipinfo-$DATE_EXEC.txt'
if [ -n "$SSH_CLIENT" ]; then
IP=$(echo $SSH_CLIENT | awk '{print $1}')
PORT=$(echo $SSH_CLIENT | awk '{print $3}')
HOSTNAME=$(hostname -f)
IPADDR=$(hostname -I | awk '{print $1}')
curl http://ipinfo.io/$IP -s -o $TMPFILE
CITY=$(cat $TMPFILE | jq '.city' | sed 's/"//g')
REGION=$(cat $TMPFILE | jq '.region' | sed 's/"//g')
COUNTRY=$(cat $TMPFILE | jq '.country' | sed 's/"//g')
ORG=$(cat $TMPFILE | jq '.org' | sed 's/"//g')
TEXT="[CWP - 103.65.yyy.xxx] SSH Login%0A $DATE_EXEC: User ${USER} logged in to $HOSTNAME ($IPADDR) from $IP - $ORG - $CITY, $REGION, $COUNTRY on port $PORT %0A%0A---%0AAuthor by Aditya Maulana"
curl -s --max-time $TIMEOUT -d "chat_id=$USERID&disable_web_page_preview=1&parse_mode=Markdown&text=$TEXT" $URL > /dev/null
rm $TMPFILE
fi
$ sudo chmod +x /etc/profile.d/ssh-telegram.sh