forked from gianluca-mascolo/ssh-telegram-notifier
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsshrc
More file actions
18 lines (16 loc) · 771 Bytes
/
Copy pathsshrc
File metadata and controls
18 lines (16 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash
export LANG=C
TELEGRAM_CHAT_ID="ddddddd"
TELEGRAM_BOT_TOKEN="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
LOGGED_USER="$(whoami)"
LOGGED_HOST="$(hostname -f)"
LOGGED_IP="$(echo "$SSH_CONNECTION" | awk '{ print $1 }')"
LOGGED_PORT="$(echo "$SSH_CONNECTION" | awk '{ print $2 }')"
NOW="$(TZ=UTC-3 date +'%b %d %Y %r')"
MESSAGE="$(echo "<strong>SSH Login Notification</strong>\n\nHost: $LOGGED_HOST\nUser: $LOGGED_USER\nIP: $LOGGED_IP:$LOGGED_PORT\nTime: $NOW")"
/usr/bin/curl --silent --output /dev/null \
--data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \
--data-urlencode "text=${MESSAGE}" \
--data-urlencode "parse_mode=HTML" \
--data-urlencode "disable_web_page_preview=true" \
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage"