A simple "Ronseal" function, that repeats a specified command until it fails with an error - i.e. returns a non-zero return code.
I like to create an alias for the function (in ~/.bash_aliases,
or simmilar), i.e.
source rue.sh
alias rue='repeatUntilError'Then you can use the function, and get help more easily:
$ rue
repeatUntilError [ OPTIONS... ] -- CMD
Runs the CMD and checks it completed successfully before running it again, otherwise exits.
OPTIONS:
-h print this help message and exit
-n <message> send a system notification to alert the user the loop has finished
-s [file] play a sound when the loop has finished, optionally specify a sound file
-- tells the program there are no more options, all further args are the CMD to run
EXAMPLE:
$ repeatUntilError -s -n 'Random "a" found' -- 'grep -v a <( head -c 8 /dev/urandom )'
this will search random 8 character strings until 'a' is found, then stop and notify
I use it to restart a short-lived DB tunnel:
repeatUntilError -s -n 'DB tunnel collapsed' -- \
kubectl --context=foo port-forward postgres-proxy 5432This way I don't have to keep doing it manually, the function reruns the tunnel command after the connection closes. When the command finally fails, it plays a sound and sends an alert displayd by the standard OS notification process.
The script uses the following utilities:
notify-send, for the OS notifications (text)cvlc, a part of thevlcinstallation, for playing sounds