Skip to content

Instantly share code, notes, and snippets.

@timebotdon
Last active January 17, 2025 07:49
Show Gist options
  • Save timebotdon/87d636651260d47f53ece7cbca8d4294 to your computer and use it in GitHub Desktop.
Save timebotdon/87d636651260d47f53ece7cbca8d4294 to your computer and use it in GitHub Desktop.
Simple shell script to forward logs to a Telegram bot.
#!/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