Last active
May 31, 2019 17:27
-
-
Save Mehran/f1df57b342c54a0ac019deaaf4a809b8 to your computer and use it in GitHub Desktop.
Bot that posts SSH logins to Telegram
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
KEY="<your bot token>" | |
URL="https://api.telegram.org/bot$KEY/sendMessage" | |
TARGET="<your chat ID>" # Telegram ID of the conversation with the bot, get it from /getUpdates API | |
TEXT="User *$PAM_USER* logged in on *$HOSTNAME* at $(date '+%Y-%m-%d %H:%M:%S %Z') | |
Remote host: $PAM_RHOST | |
Remote user: $PAM_USER | |
Service: $PAM_SERVICE | |
TTY: $PAM_TTY" | |
PAYLOAD="chat_id=$TARGET&text=$TEXT&parse_mode=Markdown&disable_web_page_preview=true" | |
# Run in background so the script could return immediately without blocking PAM | |
curl -s --max-time 10 --retry 5 --retry-delay 2 --retry-max-time 10 -d "$PAYLOAD" $URL > /dev/null 2>&1 & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment