I would like to be able to interrupt watch if execution of command was successful. In effect, I'm looking for a reverse behaviour than that offered via --errexit. As per man:

-e, --errexit Freeze updates on command error, and exit after a key press.


The command:

ping -c 3 www.google.com

Fails due to the patchy connection*. I can re-run in the following manner to see when the connection is back:

watch -n 1 'ping -c 3 www.google.com'

I would like to stop watch if ping executes with no error.

* I'm not looking to find a better of way of verifying connectivity. The ping examples comes from using a mobile phone connection when on the train with mobile phone loosing signal every so often.


Since you would start receiving pings once your network connection has been restored, start the watch after your connection has dropped and tell it to exit once the output changes:

watch -g -n 1 ping -c 3 www.google.com

As soon as you start receiving pongs, watch will exit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.