0

I am trying to get a returned value with the 2 digits temp with sensors command, wich shows me this:

sensors coretemp-isa-0000 Adapter: ISA adapter Core 0: +40.0°C (high = +85.0°C, crit = +95.0°C)
Core 8: +35.0°C (high = +85.0°C, crit = +95.0°C)
Core 9: +40.0°C (high = +85.0°C, crit = +95.0°C)
Core 10: +38.0°C (high = +85.0°C, crit = +95.0°C)

coretemp-isa-0001 Adapter: ISA adapter Core 0: +38.0°C (high = +85.0°C, crit = +95.0°C)
Core 1: +37.0°C (high = +85.0°C, crit = +95.0°C)
Core 9: +30.0°C (high = +85.0°C, crit = +95.0°C)
Core 10: +31.0°C (high = +85.0°C, crit = +95.0°C)

With the following command I have been able to get returned the values, but I need to get values one by one:

Command: sensors | awk '{if (match($0, "Core 0")){printf("%d",$3);} }' Returns: 4038

Is there a way to get first or sencond occurrence one by one?

Thanks in advance for your help.

  • accurate data samples and expected results please – mug896 Feb 2 '17 at 14:15
  • Hi Mug, if I run this same comand on a single processor machine I get a return of the actual Core temp, for example on server 1 I run the same command (sensors | awk '{if (match($0, "Core 0")){printf("%d",$3);} }') and get a 2 digits number back, like 31, but on the 2 processors server as there are 2 Core 0 I get both numers back like 3131 – Javier Gomez Feb 2 '17 at 14:33
0
$ sensors | sed -rn 's/.*Core 0:\s+([^ ]+).*/\1/p'
+40.0°C
+38.0°C

$ sensors | sed -rn 's/.*Core 0:\s+.([0-9.]+).*/\1/p'
40.0
38.0

$ sensors | sed -rn 's/.*Core 0:\s+.([0-9]+).*/\1/p'
40
38
  • Hi Mug, thanks a lot for your quick reply!, I have tryed this solution but non of them is returning a output (at least on screen), my system is a Centos 6, not sure if that helps or is relevant. – Javier Gomez Feb 2 '17 at 16:39
  • what version your grep is ? – mug896 Feb 2 '17 at 16:42
  • I have updated the answer using sed – mug896 Feb 2 '17 at 16:49
  • grep (GNU grep) 2.20, I'll try with sed and let you know if that worked – Javier Gomez Feb 2 '17 at 16:50
  • I think your sample data is not the same as real one. i have tested with data in your question – mug896 Feb 2 '17 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.