Last active
January 17, 2025 07:49
-
-
Save timebotdon/87d636651260d47f53ece7cbca8d4294 to your computer and use it in GitHub Desktop.
Simple shell script to forward logs to a Telegram bot.
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 | |
## Credit: admin@Shellhacks | |
## Article URL: https://www.shellhacks.com/telegram-api-send-message-personal-notification-bot/ | |
## Define Vars | |
token= #Telegram bot API token | |
chatID= #Telegram Chat ID | |
sendURL="https://api.telegram.org/bot$token/sendMessage" | |
logFile="/var/log/auth.log" | |
## Tail logs and send to telegram bot. | |
function sendLog { | |
tail -fn0 $logFile | \ | |
while read line; do | |
echo "$line" | |
if [ $? = 0 ] | |
then | |
curl -s -X POST $sendURL -d chat_id=$chatID -d text="$line" | |
fi | |
done | |
} | |
sendLog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment