brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: watch -e freezes on the first error so you can still read it

Watch
~/tips/tip-linux-watch-errexit

watch -e -n 5 curl -fsS -o /dev/null https://example.com/health

Stop refreshing as soon as the watched command fails.

Watching a flaky service has one annoyance: the error flashes by, the next run succeeds, and the evidence is gone.

-e (or --errexit) freezes the screen when the command returns a non zero exit code:

watch -e -n 5 curl -fsS -o /dev/null https://example.com/health

As long as the request works, it repeats every five seconds. When curl fails (-f makes an HTTP error count too), the output stays put with a notice, and watch exits after you press a key. Its exit code is then the one the command gave, so you can look it up.

Add -b if you want a beep on failure and you’re working in another window:

watch -b -e -n 5 ping -c 1 -W 2 example.com

I’d use this for the “it only breaks now and then” kind of problem, because it catches the first failure with its message intact and you don’t have to sit and stare.

It stops at the first failure, so you learn nothing about how often it happens after that. For a long record, write results to a log file in a loop instead. A command that ends in a pipe reports the status of the last part only, which can hide the failure you’re after. These options belong to the procps version of watch.

Further reading: watch(1) manual page

More Watch tips On the watch: Settings > SOS > Fall Detection On the watch: Settings > Noise > Noise Threshold > pick a level Open Camera Remote on the watch High Heart Rate Notifications > threshold watch -c ls --color=always -l /var/log All Watch tips (17) All topics

Link