Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
problem getting coloured output when using watch
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
as.gentoo
Guru
Guru


Joined: 07 Aug 2004
Posts: 319

PostPosted: Fri Jun 16, 2017 8:17 am    Post subject: problem getting coloured output when using watch Reply with quote

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
View user's profile Send private message
massimo
Veteran
Veteran


Joined: 22 Jun 2003
Posts: 1226

PostPosted: Fri Jun 16, 2017 9:04 am    Post subject: Reply with quote

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
View user's profile Send private message
as.gentoo
Guru
Guru


Joined: 07 Aug 2004
Posts: 319

PostPosted: Fri Jun 16, 2017 12:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
josephg
l33t
l33t


Joined: 10 Jan 2016
Posts: 783
Location: usually offline

PostPosted: Fri Jun 16, 2017 1:02 pm    Post subject: Reply with quote

what package is watch part of? i don't seem to have watch on my gentoo.
Back to top
View user's profile Send private message
as.gentoo
Guru
Guru


Joined: 07 Aug 2004
Posts: 319

PostPosted: Fri Jun 16, 2017 3:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
josephg
l33t
l33t


Joined: 10 Jan 2016
Posts: 783
Location: usually offline

PostPosted: Fri Jun 16, 2017 3:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
as.gentoo
Guru
Guru


Joined: 07 Aug 2004
Posts: 319

PostPosted: Fri Jun 16, 2017 4:30 pm    Post subject: Reply with quote

josephg wrote:
thanks as.gentoo, my procps has -ncurses. that's why
[...]
My pleasure.
Back to top
View user's profile Send private message
freke
l33t
l33t


Joined: 23 Jan 2003
Posts: 977
Location: Somewhere in Denmark

PostPosted: Sat Jun 17, 2017 10:12 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum