Justin Lin āŸ”

Unix

A small collection.

Utilities

Run in a loop with delay

Lightweight way to run something in a loop with a delay. No need to actually write the loop. This will run the command every 5 seconds:

watch -n 5 $command

For example, this will run until output of a curl request changes and notify telegram. You can use tmux/screen to keep the command alive.

watch -n 60 -g -d -x curl -s 'https://google.com'; telegram-send "change detected"

Gotchas

If you want to run a command remotely, you can use ssh to run the command. However, if you want to run a command with an & in it, you need to escape it. Here the ā€œ&d=eā€ part of the URL gets swallowed by the shell:

ssh oracle "echo a?b=c&d=e"
# output: a?b=c


Back