A few months ago we published an article in which we showed how with a simple script programmed in Bash we could improve the security of our Raspberry Pi. Today we bring you an updated version of that script in Python.
The article mentioned above can be found at: How to Improve Raspberry Pi Security [2020].
Here is an example of what these notifications would look like:

You must have previously created your Telegram bot. If you still don’t know how to create it, follow the next manual:
https://sudosu.info/how-to-create-a-bot-in-telegram/
In order to be able to use the variables in the .env file, you will also need to install the Dotenv python library:
To install it, all you need to do is download the program to your scripts folder.
All the parameters necessary to run the script must be filled in the .env file.

Note that the script will not work if you use decimals. We recommend that you only fill in the TOKEN and ID variables for your Telegram bot.
Thanks to a Cronjob in Raspbian, we can create the timer to tun the script every 30seconds/1minute.
Run the following command to edit the Cron editor:
Add the following line at the end of the cron file:

If you did the configuration correctly you will receive an alarm when the script detects something out of range.
Well and finally, we hope this script helps you to improve the security of your Raspberry. Feel free to edit and improve it as you like, we would love to know what things you would improve in this script.
Leave a Reply