Using $PROMPT_COMMAND to beep depending on success/failure
blinux.list at thechases.com
Wed Apr 20 21:24:19 UTC 2016
On April 20, 2016, Jude DaShiell wrote:
> Tim, thanks. I have an application in mind for this.
> What I've been doing so far to test network connected status was:
> ping -c 5 www.google.com|grep %
> That returns a line of output giving packet thruput statistics and
> if I have 0 percent packet loss I know my network is up. I just
> need to figure out how to itegrate this.
I'd simplify the test to something like
ping -c 1 -W 2 www.google.com
which issues one ping and waits 2 seconds for a reply without the
need for grepping. If it doesn't hear back, it will exit with a
non-zero exit code, so you can simplify the test to
PROMPT_COMMAND='ping -c 1 -W 2 www.google.com && play -qn synth sin F3
trim 0 0 0.1 fade 0 0.1 0.05 vol 0.2 || play -qn synth square F4 trim
0 0.1 fade 0 0.1 0.05'
which will do the ping each time the prompt is displayed, and chirp
based on success/failure. This does mean that you might have up to a
2-second wait after every command if your network is down.
If you really do want to sample the percentages, it would take a
little more effort and might be worth running in the background and
caching the result, then checking that cache in your PROMPT_COMMAND.
More information about the Blinux-list