by Kim_Bruning · 4y ago · 0 comments
watch -n 600 -c 'curl -s v2.wttr.in/'
This ALMOST works, but somehow it messes up the formatting for me. For some reason watch doesn't pass through formatting cleanly or so?
You can try to run it with any command that has ANSI output, and you will see it.
As a simple alternative, you write your own 'watch' like this:
while true; do curl -s wttr.in; sleep 60; clear; done
while sleep 60; do clear; curl -s wttr.in; done
Otherwise, I very often get a loop which stubbornly refuses to abort, and I have to hammer both Ctrl-C and Ctrl-\ to make it stop. The downside is, of course, that I have to wait 60 seconds (in this case) the first time. When this is a problem, I just unroll the loop slightly and add an extra invocation to the beginning: clear; curl -s wttr.in; while sleep 60; do clear; curl -s wttr.in; done
This could be generalized into a terminal watch function: termwatch(){ delay="$1"; shift; clear; "$@"; while sleep "$delay"; do clear; "$@"; done; }
termwatch 60 curl -s wttr.inAccording to The Fine Manual: watch --color (-c for short) , should render color correctly, eg.
watch --color ls --color
but watch --color curl -s v2.wttr.in
doesn't quite play ball.In the end I went with something like your solution. I didn't need to put the sleep 60 as the first operation though.
#!/bin/bash
while true; do
clear
curl -s v2.wttr.in
sleep 100
done
^C breaks out of this loop just fine on my system.It might be different when run as a script (with a separate shell process) to when run as an explicit loop in an interactive shell, or a shell function.