Recently, I’ve been busy thinking of automation and remote control applications. In this direction, I wrote a tiny telegram bot in python to remotely power off my linux box.
The bot itself is extremely simple. All it does is listen to incoming texts from a specific telegram user, and if the command is the trigger phrase, it fires off the shutdown script of the computer its running on. If you tell it anything other than the trigger phrase, it simply echoes it back to you, so you know its alive.
The only hurdle I had to jump over on this project were the facts that
- In Linux, you need to be root to run
- Its unwise to just run stuff as root
sudonormally asks for a password
This I circumvented by referring to the sudo page on Arch Wiki, and letting my user execute
/usr/sbin/poweroff without needing a password prompt. I am not sure how secure it is, but I don’t think its too unsecure.
The code, as always, is available on my github.
Special thanks to my good friend Rajratan for reminding me to make a blog post about this bot.
- [Update 3] Wall Clock
- [Bjorn] Journal Entry for Session 12 April 2020