Answer the question
In order to leave comments, you need to log in
Action on the server when connecting via ssh?
Good afternoon, I would like to try to make it so that when I successfully connect to the server (ssh, ftp), I receive a letter in the mail. Is it real to do? If yes, can you give me some hints or examples how to do it?
Answer the question
In order to leave comments, you need to log in
Try your cart bot. Notifications are an order of magnitude more convenient and faster than mail.
I will describe for debian. (for other distros it won't be much different). If not you, then maybe someone else will need everything ready:
Create a file /usr/local/bin/telegram_alert.sh with the following content:
#!/bin/bash
KEY="АПИ_КЛЮЧ:ВАШЕГО_БОТА"
URL="https://api.telegram.org/bot$KEY/sendMessage"
TARGET="айдишник_контакта_или_группы_куда_слать_уведомления"
DATE1="$(date "+%H:%M:%S")"
DATE2="$(date "+%d %B %Y")"
GEO="$(curl ipinfo.io/$PAM_RHOST)"
TEXT="*$PAM_USER* залогинился на *$HOSTNAME*
Время: $DATE1
Дата: $DATE2
Адрес: $PAM_RHOST
Service: $PAM_SERVICE
TTY: $PAM_TTY
GEO: ${GEO}"
PAYLOAD="chat_id=$TARGET&text=$TEXT&parse_mode=Markdown&disable_web_page_preview=true"
curl -s --max-time 10 --retry 5 --retry-delay 2 --retry-max-time 10 -d "$PAYLOAD" $URL > /dev/null 2>&1 &
session optional pam_exec.so type=open_session seteuid /usr/local/bin/telegram_alert.sh
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question