What if running Linux commands were as easy as pressing a button in Telegram?

go dev.to

As a computer enthusiast, I’m constantly dealing with a large number of Linux servers, which means I’m constantly connecting to them over SSH and running different commands in the terminal.

A lot of these servers are work-related, and I also have a few personal servers.

This is the story of one of the challenges I faced on my personal servers, which eventually made me roll up my sleeves and build a program called Telegram Commander.

😅 Maybe this has happened to you too

One evening, after a long day of work, I was lying on the couch in front of the TV, ready to watch the latest episode of our favorite series with my wife.

Then I realized the TV couldn’t connect to my home server, so we couldn’t watch the episode that had already been automatically downloaded in amazing quality.

I really didn’t feel like getting up, sitting at my desk, connecting to the server, and troubleshooting the problem.

So I SSH’d into my home server using my phone and, with quite a bit of struggle, fixed the issue.

But as you probably know, running terminal commands on a phone comes with its own challenges.

That’s when I thought:

It would be great if I could handle these repetitive tasks through a Telegram bot, right inside Telegram, just by pressing a few buttons.

And this story kept happening again and again in different situations:

_

  • When you’re in the car and realize your family messaging service has stopped working.
  • When you’re lying in bed and realize you need to restart your home internet connection. And so on... _

What’s interesting is that many of these problems usually had a very specific solution, and I already knew exactly which command I needed to run.

So I decided to build a solution for it using my favorite programming language, Golang.

🤖 What was the program supposed to do?

The idea was to build a Telegram bot with these requirements:

  • Easily define buttons and tell each button which command it should execute.
  • Group buttons into collections.
  • Add icons to buttons when needed.
  • After each command is executed, report its output and whether it succeeded or failed.
  • Be secure and only allow authorized users to interact with the bot.
  • Telegram is blocked in Iran, so it should support connecting to Telegram through a proxy.
  • Be simple to install and run on Linux servers.
  • Manage everything through a simple configuration file.

I got to work, and the result was Telegram Commander — a Telegram bot builder that turns Linux commands into Telegram bot buttons using a configuration file.

It’s open source and completely free, and you can inspect everything in its GitHub repository so you can see exactly how it works.

🌐 Website:
https://telecommander.ir/

📦 Source code:

https://github.com/azolfaghrj/telegram-commander

The website contains all the documentation and tutorials you need, available in 7 languages

So, what are you waiting for?

🚀 Easy Setup and Execution

Overall, getting started only takes a few simple steps:

  1. Download the latest release from GitHub.
  2. Choose the executable that matches your server’s CPU architecture.
  3. Copy the sample configuration file and enter your username and bot token.
  4. Run the program and send a message to the bot on Telegram.

That’s it.

And you’ll end up with something like this:

Source: dev.to

arrow_back Back to Tutorials