View previous topic :: View next topic |
Author |
Message |
as.gentoo Guru
Joined: 07 Aug 2004 Posts: 319
|
Posted: Fri Jun 16, 2017 8:17 am Post subject: problem getting coloured output when using watch |
|
|
Hello everyone!
I want to keep my GPUs temperature visible in a terminal. The commands that query and present what I need work. But repeatedly executing those by using 'watch' does not work. Quote: | ------------------- command w/o 'watch' -----------------------------
sensors | grep temp1 | grep --color=always "+[0-9][0-9].[0-9] C "
--------- RESULT -------------------------------------------------------
temp1: +48.0 C (high = +95.0 C, hyst = +3.0 C)
temp1: +46.0 C (high = +95.0 C, hyst = +3.0 C) | BTW: I intentionally used [ quote ] here because you can not colorise [ code ] sections.
Next is the same but using 'watch' Code: | ---------- command w/ 'watch' ------------------------------------------
watch -d -n 10 sh -c 'sensors | grep temp1 | grep --color=always "+[0-9][0-9].[0-9] C "'
--------- RESULT -------------------------------------------------------
Every 10.0s: sh -c sensors | grep temp1 | grep --color=always "+[0-9][0-9].[0-9] C " <date>
temp1: ^[01;31m^[K+48.0 C ^[m^[K(high = +95.0 C, hyst = +3.0 C)
temp1: ^[01;31m^[K+47.0 C ^[m^[K(high = +95.0 C, hyst = +3.0 C) | So the color codes are there but not interpreted - since I didn't use 'watch --color' the result is just right. However, adding '--color' right behind 'watch' results in
Code: | Every 10.0s: sh -c sensors | grep temp1 | grep --color=always "+[0-9][0-9].[0-9] C " <date>
temp1: p1: |
Code: | $ man watch | grep -A1 '\-\-color'
-c, --color
Interpret ANSI color and style sequences. | Aren't those codes "made" by grep ANSI color sequences?
What's my error in reasoning?
Thanks in advance
This is the script version Code: | ---------- SOURCE ------------------------------------------------------
#!/bin/bash
set -o verbose
set -o xtrace
watch -c -n 10 -d sh -c 'sensors | grep temp1 | grep --color=always "+[0-9][0-9].[0-9] C "'
--------- RESULT -------------------------------------------------------
Every 10.0s: sh -c sensors | grep temp1 | grep --color=always "+[0-9][0-9].[0-9] C " <date>
temp1: p1:
------------------------------------------------------------------------ |
As the output is the same I wonder why there is no debug output at all despite the two 'set' commands. Does 'watch' block those settings? … But that's a different matter. |
|
Back to top |
|
|
massimo Veteran
Joined: 22 Jun 2003 Posts: 1226
|
Posted: Fri Jun 16, 2017 9:04 am Post subject: |
|
|
Does it work with the following command:
Code: | watch -c -d -n 10 'sensors | grep temp1 | grep --color=always "+[0-9][0-9].[0-9] C "' |
_________________ Hello 911? How are you? |
|
Back to top |
|
|
as.gentoo Guru
Joined: 07 Aug 2004 Posts: 319
|
Posted: Fri Jun 16, 2017 12:36 pm Post subject: |
|
|
massimo wrote: | Does it work with the following command:
Code: | watch -c -d -n 10 'sensors | grep temp1 | grep --color=always "+[0-9][0-9].[0-9] C "' |
| No, it doesn't. :-\
I am using the "latest" live-DVD. If it should work like that maybe there is a bug in the included version of 'watch'. That would be sys-process/procps-3.3.11-r3. |
|
Back to top |
|
|
josephg l33t
Joined: 10 Jan 2016 Posts: 783 Location: usually offline
|
Posted: Fri Jun 16, 2017 1:02 pm Post subject: |
|
|
what package is watch part of? i don't seem to have watch on my gentoo. |
|
Back to top |
|
|
as.gentoo Guru
Joined: 07 Aug 2004 Posts: 319
|
Posted: Fri Jun 16, 2017 3:29 pm Post subject: |
|
|
Code: | $ which watch
/usr/bin/watch
$ equery b /usr/bin/watch
* Searching for /usr/bin/watch ...
sys-process/procps-3.3.11-r3 (/usr/bin/watch)
$ equery f sys-process/procps | grep /usr/bin
/usr/bin
/usr/bin/free
/usr/bin/pgrep
/usr/bin/pidof
/usr/bin/pkill
/usr/bin/pmap
/usr/bin/pwdx
/usr/bin/slabtop
/usr/bin/tload
/usr/bin/top
/usr/bin/uptime
/usr/bin/vmstat
/usr/bin/w
/usr/bin/watch |
So it should be installed on every gentoo box, right? |
|
Back to top |
|
|
josephg l33t
Joined: 10 Jan 2016 Posts: 783 Location: usually offline
|
Posted: Fri Jun 16, 2017 3:57 pm Post subject: |
|
|
thanks as.gentoo, my procps has -ncurses. that's why
Code: | $ equery f procps | grep bin
/bin
/bin/kill
/bin/ps
/usr/bin
/usr/bin/free
/usr/bin/pgrep
/usr/bin/pidof
/usr/bin/pkill
/usr/bin/pmap
/usr/bin/pwdx
/usr/bin/tload
/usr/bin/uptime
/usr/bin/vmstat
/usr/bin/w
/usr/sbin
/usr/sbin/sysctl |
_________________ "Growth for the sake of growth is the ideology of the cancer cell." Edward Abbey |
|
Back to top |
|
|
as.gentoo Guru
Joined: 07 Aug 2004 Posts: 319
|
Posted: Fri Jun 16, 2017 4:30 pm Post subject: |
|
|
josephg wrote: | thanks as.gentoo, my procps has -ncurses. that's why
[...] | My pleasure. |
|
Back to top |
|
|
freke l33t
Joined: 23 Jan 2003 Posts: 977 Location: Somewhere in Denmark
|
Posted: Sat Jun 17, 2017 10:12 am Post subject: |
|
|
Code: | watch -c -n 10 'sensors | grep Core | grep --color=always "+[0-9][0-9].[0-9]°C"' |
works for me; adding -d mess it up a bit (if any digit is changed it's getting highlighted.
Code: | * sys-process/procps
Available versions: 3.3.12(0/5) ~3.3.12-r1(0/5)
IUSE (all versions): elogind +kill modern-top +ncurses nls selinux static-libs systemd test unicode
Installed versions: Version: 3.3.12
Date: 09:16:37 PM 05/25/2017
USE: kill ncurses nls unicode -modern-top -selinux -static-libs -systemd -test |
|
|
Back to top |
|
|
|