As part of my work I often have to run time-intensive jobs, both locally and remotely. In order to not have to actively check on them before they finish I have written a small utility in Bash to observe select tasks and send me a message upon their completion.
This utility is based on Telegram-Alert by Omar Richardson and it requires the following two prerequisites:
- internet access for
curl
orwget
telegram-alert
to be executable
Setting up Telegram-Alert
First download and set up the telegram-alert
system according to the steps outlined in the readme.
Place the telegram-alert
executable in an appropriate location in your $PATH
and try sending a couple messages from a new shell instance.
Creating the observer tool
Create a new executable file named tgo
in with the following content:
#!/bin/bash
### __author__ = "joseti.me/about"
### __version__ = "1.0.1"
### __license__ = "GPLv3"
###
### very basic shell utility script to observe a process using telegram-alert
### requires 'telegram-alert' to be successfully set up on system working
### command syntax: tgo <command [arguments]>
###
# run all parameters as-is in bash, first parameter assumed to be valid executable
"$@"
# have telegram-alert send a message with executed command, parameters and exit code
telegram-alert "Command '$@' finished with exit code $?"
Place the tgo
executable in an appropriate location, preferrably the same location as telegram-alert
and reload your shell.
Using the observer tool
Observing a process is now simple, just prepend tgo
in front of the call to be observed, similar to how nohup
is used.
tgo true
tgo false
echo "Testing 1" && tgo echo "Testing 2" && echo "Testing 3"
You will now get a Telegram message from your bot as soon as the observed process has exited.