A simple Bash shell script to send messages to Telegram messenger using the Curl command. Then you will use this script to send a notification on every ssh login into your server.
Report Bug
·
Request Feature
To send a message to Telegram group or channel, you should first create your own bot. Just open Telegram, find @BotFather and type /start
. Then follow instructions to create bot and get token to access the HTTP API.
Create a new Channel in Telegram and add your bot as a member. So your bot could send messages to the Channel.
In order to get Channel Id, first, post any message to the Channel. Then use this link template to get Channel Id:
https://api.telegram.org/bot<YourBOTToken>/getUpdates
Here is a response example:
{
"ok":true,
"result": [
{
"update_id":123,
"channel_post": {
"message_id":48,
"chat": {
"id":-123123123, // this is your channel id
"title":"Notifications",
"type":"channel"
},
"date":1574485277,
"text":"test"
}
}
]
}
git clone https://github.com/vi-dev0/login-alert-bot.git
Add bot token and chat ID in telegram-send.sh
#!/bin/bash
GROUP_ID=<group_id>
BOT_TOKEN=<bot_token>
chmod +x telegram-send.sh
chmod +x login-notify.sh
In order to use this script from everywhere and type telegram-send instead ./telegram-send.sh
add it to /usr/bin/
folder
sudo mv telegram-send.sh /usr/bin/telegram-send
Owner of all files in /usr/bin is root user. So let's do the same with our script:
sudo chown root:root /usr/bin/telegram-send
You can test it: telegram-send "Test message"
Move login-notify.sh
script to /etc/profile.d/
folder
sudo mv login-notify.sh /etc/profile.d/login-notify.sh
Distributed under the MIT License. See LICENSE.txt
for more information.
Mr Vi - @vi_dev0
Project Link: Login Alert Bot