You are not logged in.
Pages: 1
Kernel >= 2.6.36.x supports temperature monitoring for ATI cards (HD4xxx or later) using the open source drivers. Great! Right? So, here is the sensors output:
$ sensors
radeon-pci-0200
Adapter: PCI adapter
temp1: +69.0°C
acpitz-virtual-0
Adapter: Virtual device
temp1: +26.8°C (crit = +100.0°C)
temp2: +0.0°C (crit = +100.0°C)
coretemp-isa-0000
Adapter: ISA adapter
Core 0: +56.0°C (high = +80.0°C, crit = +90.0°C)
coretemp-isa-0001
Adapter: ISA adapter
Core 2: +54.0°C (high = +80.0°C, crit = +90.0°C)
Basically, I need a one-liner that will:
- Find the line that starts with "radeon-pci",
- Go 2 lines below,
- Extract "69.0" from that line,
- Return it without a newline character at the end.
I'd really like to learn how to do this myself, so if you can also post how your script works, that'll be great. Thanks!
Last edited by dcc24 (2010-09-11 20:29:07)
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
Offline
I'm sure someone can do this more cleanly with only sed, but I'll bite:
sensors | grep -A2 "radeon" | sed -n 's/temp1:[[:blank:]]\++\([[:digit:]\.]\+\).*/\1/p'
This one has a lot of whitespace at the end and a newline character. I can't fix it since I have no idea how sed works
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
Probably this is quite bloated, but I would start with:
sensors | awk 'BEGIN {line = -1} {if ($0 ~ /radeon-pci-0200/) { line=NR+2;} if (NR == line) {print $2}}'
Of course you can also do
cut -d\ -f14 /proc/acpi/thermal_zone/THRM/temperature
But that feels like cheating
Offline
Perhaps you could describe the target application this is being used in...
My latest OCD edit doesn't show any white space after the end of the matched token:
$ sensors | sed -n '/radeon/,+2s@.*+\([[:digit:]\.]\+\).*@\1@p' | cat -At
69.0$
Last edited by falconindy (2010-09-11 20:55:15)
Offline
sensors | awk 'BEGIN {line = -1} {if ($0 ~ /radeon-pci-0200/) { line=NR+2;} if (NR == line) {print $2}}'
This doesn't strip the + sign, or the "degrees celcius" part, or the newline character
Of course you can also do
cut -d\ -f14 /proc/acpi/thermal_zone/THRM/temperature
But that feels like cheating
I don't have a sysfs interface for radeon (i.e THRM doesn't exist) but nice try
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
Perhaps you could describe the target application this is being used in...
My latest OCD edit doesn't show any white space after the end of the matched token:
$ sensors | sed -n '/radeon/,+2s@.*+\([[:digit:]\.]\+\).*@\1@p' | cat -At 69.0$
It is to be used in conky among some personal logging scripts.
Now this version is almost perfect! I can think of adding another sed at the end to remove the "$" (that $ doesn't come from the bash prompt, it's a real character), but there should be a cleaner way, right?
Last edited by dcc24 (2010-09-11 20:59:39)
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
ups, forgot to delete the undesired characters:
sensors | awk 'BEGIN {line = -1} {if ($0 ~ /radeon-pci-0200/) { line=NR+2;} if (NR == line) {print substr($2,2,6)}}'
Edit:
That will work as long you don't go over 100 degrees. if you do, then well need to find the character instead of putting "6", and also find a way to cool your cpu
Last edited by olvar (2010-09-11 21:01:46)
Offline
ups, forgot to delete the undesired characters:
sensors | awk 'BEGIN {line = -1} {if ($0 ~ /radeon-pci-0200/) { line=NR+2;} if (NR == line) {print substr($2,2,6)}}'
Make that "6" at the end a "4", we are all set
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
whatever | sed '/^radeon-pci/,/^$/!d' | sed -n 's/^temp.*+\(.*\)°C.*$/\1/p'
This'll output only the numbers you want, it works with all temperatures, and will work if you have more than one temperature reading.
Last edited by codycarey (2010-09-11 21:13:34)
Offline
A dirty but reliable way to get rid of all newlines:
echo -n $(<command with newlines in its output>)
So my solution would be:
echo -n $(sensors | sed -n '/^radeon-pci/,+2 s/[^+]*+\([0-9.]*\)°C/\1/p')
Works for the acpitz, coretemp (or whatever) values too.
“First principle, Clarice. Simplicity” – Dr. Hannibal Lecter
Offline
falconindy wrote:Perhaps you could describe the target application this is being used in...
My latest OCD edit doesn't show any white space after the end of the matched token:
$ sensors | sed -n '/radeon/,+2s@.*+\([[:digit:]\.]\+\).*@\1@p' | cat -At 69.0$
It is to be used in conky among some personal logging scripts.
Now this version is almost perfect! I can think of adding another sed at the end to remove the "$" (that $ doesn't come from the bash prompt, it's a real character), but there should be a cleaner way, right?
The $ at the end is an EOL character generated by cat (the -A flag). I was merely showing you that there's no whitespace after the extracted expression.
Offline
cut -d\ -f14 /proc/acpi/thermal_zone/THRM/temperature
But that feels like cheating
If you want to cheat:
grep -o [[:digit:]]* /proc/acpi/thermal_zone/THRM/temperature
Offline
The $ at the end is an EOL character generated by cat (the -A flag). I was merely showing you that there's no whitespace after the extracted expression.
I see that, but when I put your first version in conky, it generated a lot of whitespace after the expression. No idea why, though.
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
A dirty but reliable way to get rid of all newlines:
echo -n $(<command with newlines in its output>)
<command> | tr -d '\n'
Of course this will get rid of all newlines, not just trailing newlines.
Offline
Pages: 1