DEV Community

Daniel Herman
Daniel Herman

Posted on • Edited on

Run commands with notification after finishing

Have you ever wondered how to execute scripts with some notification after they finish on your local or remote machine? As a physics student, I run many simulations on remote servers or lab PCs. These days I contribute to my supervisor’s package quantarhei (also we need developers) and I need to run package tests on a regular basis. Since these tests take approximately 5 min, that is a reasonable time indeed, but our school lab can do a bit better. I don’t want to wait all this time staring at unit test output and I would like to continue in package development! So what do I do?

I tried to solve this inconvenience. Because I had VPS, I created my own Rest API, with MongoDB database and telegram bot. This way I had smartphone notifications and desktop notification with the telegram web app. This solution, however, created many different problems (which I had fun solving). I was searching for some online tools but didn’t find anything for a reasonable price or for free.

Alt Text

For my local machine I use sound notification, with these aliases in .zshrc (or .bashrc if you don’t use zsh)

alias sn1="mpg123 ~/Music/never.mp3 > /dev/null 2>&1" 
alias sn2="spd-say 'Yo'"
alias sn3="mpg123 ~/Music/doot_doot_mr_skeletal.mp3 > /dev/null 2>&1" 
...
Enter fullscreen mode Exit fullscreen mode

then simply run the following

sleep 5; sn2
Enter fullscreen mode Exit fullscreen mode

What about remote machines? I use Pushbullet together with ntfy ntfy utility! Ntfy also supports Pushover, but they do not support older versions of Android OS. You have to go to the Pushbullet website and get Access Token in the settings. Then create ntfy config file ~/.config/ntfy/ntfy.yml

backends:
    - pushbullet
pushover:
    user_key: YOUR_ACCESS_TOKEN
Enter fullscreen mode Exit fullscreen mode

Set your alias in .zsrhc (or .bashrc)

alias msg="ntfy send"
Enter fullscreen mode Exit fullscreen mode

If you do not have rights to change files outside your home folder you can also execute ntfy directly with the token

alias msg="ntfy -b pushbullet -o access_token YOUR_ACCESS_TOKEN send"
Enter fullscreen mode Exit fullscreen mode

Enjoy your notifications!

msg “ARE YOU READY?”
Enter fullscreen mode Exit fullscreen mode

Top comments (0)