Category Archives: bash

send stuff to telegram bot command-line globally


As you have seen in the other posts, I like to use a telegram bot for my notifications with domoticz. But I also like to use it to notify me from scripts.

After a while I found myself adding the same long ‘curl etc etc’-commands in every script, so it was time to create a little script that holds everything I need and can be used globally.


You need to have a telegram bot already up and running. Like earlier is found this tutorial to be pretty good.


create a new file called ‘tg’ and ‘chmod +x’ it. Then edit it like so:

bot_id="insert your bot id here"
api_key="your api-key here"
chat_id="your chat-id here"
curl -s "$bot_id:$api_key/$action?chat_id=$chat_id&text=$1"

After that create a symlink to ‘/bin/tg’. Because ‘/bin’ is usually in the ‘search path’ for commands it will be accessible from everywhere.


now you can use it ‘globaly’ from scripts or command line:

root@host:/$ tg "blabla bla"

And it will send your text to your Telegram bot:


cleanup script to put files into date folders


I made a backup-script which just dumps it’s files into 1 folder, but that got messy pretty quickly. I needed a script which could cleanup files (*.tgz) from a folder and put them into their respective date-folder.


cd /rootfolder/to/cleanup
for x in *.tgz; do
d=$(date -r "$x" +%Y-%m-%d)
mkdir -p "$d"
mv -- "$x" "$d/"