Skip to content

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.

License

Notifications You must be signed in to change notification settings

vi-dev0/login-alert-bot

Repository files navigation

Contributors Forks Stargazers Issues MIT License


Logo

Login Alert Bot

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

Product Name Screen Shot

How to use

Create telegram bot

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 Channel

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"
      }
    }
  ]
}

Clone the repo

git clone https://github.com/vi-dev0/login-alert-bot.git

Add token and chat ID

Add bot token and chat ID in telegram-send.sh

#!/bin/bash
    
GROUP_ID=<group_id>
BOT_TOKEN=<bot_token>

Add permissions

chmod +x telegram-send.sh
chmod +x login-notify.sh

Move to scripts folder

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

Now re-login to your web server and check it works.

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Mr Vi - @vi_dev0

Project Link: Login Alert Bot

(back to top)

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Languages