You are not logged in.
I'm making a small script for personal use, whose purpose is to output the state of my cooling devices in a nice way. For now, this is what I have, and, although it may be a bit dirty, it works:
( echo 'n type max cur' ; for P in /sys/class/thermal/cooling_device* ; do echo -n "$P " | tr -d '/sys/class/thermal/cooling_device' ; cat "$P"/{'type','max_state','cur_state'} | tr '\n' ' ' ; echo ; done) | column -t
Its output, in my machine, is the following:
n type max cur
0 Processor 10 0
1 Processor 3 0
2 Fan 1 0
3 Fan 1 0
4 Fan 1 1
5 Fan 1 1
I would like to colorize the output, but using either tput or color escape codes confuses column. Looking for a way to solve this in column has not succeeded; it seems it doesn't have any option to strip escape codes, or to ignore them. So, what can I do? I've thought about modifying the already-printed text, but that doesn't seem to be a very 'elegant' solution (I can't imagine how to do it, either).
Any ideas would be greatly appreciated. Good readings are also welcomed.
Thanks in advance,
Kalrish
Last edited by Kalrish (2013-06-09 12:24:07)
Offline
Try using printf instead of column.
#!/bin/bash
black='\e[0;30m'
red='\e[0;31m'
for d in /sys/class/thermal/cooling_device*; do
cd "$d"
x=(${d: -1:1} $(cat type max_state cur_state))
printf "${black}%2d %-10s ${red}%2d${black} %2d\n" ${x[@]}
done
Last edited by rockin turtle (2013-06-09 09:05:13)
Offline
Thanks, rockin, printf solves my problem.
Marking as solved. Best regards,
Kalrish
Offline