You are not logged in.

#1 2018-09-09 00:00:57

Moltke
Member
Registered: 2016-07-12
Posts: 59

(SOLVED) cpu tem widget in awesome wm

Hi everyone! Hope you're all having a nice life! smile
I recently started using awesome wm 4.2 and really like it; has significantly improved my workflow. I wanted to create a widget showing cpu temp, and I made it following instructions from here https://awesomewm.org/apidoc/classes/aw … watch.html

like this:

wibox.widget.textbox(' | '),

awful.widget.watch('bash -c "cat/sys/class/hwmon/hwmon0/device/temp1_input"', 15),

wibox.widget.textbox(' | '),

awful.widget.watch('bash -c "cat /sys/class/hwmon/hwmon0/device/temp3_input"', 15),

It works, but it shows big numbers i.e 43000 instead of 43. How can I change that? and if possible 43°C.

I've already searched the forum for answers and found this post https://bbs.archlinux.org/viewtopic.php?id=168537 which is from 2013 and which answer doesn't help in my case.

Thanks in advance for your answers! Any help/advice is much appreciated! smile

Last edited by Moltke (2018-09-09 05:08:37)


Judges have decimated, meanings of our laws, already guilt? something has a flow, wrongly accused, blindly confused, open your eyes, wake up realize!

Offline

#2 2018-09-09 00:04:57

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: (SOLVED) cpu tem widget in awesome wm

Please use code tags, not that godawful highlighting, when pasting to the boards: https://wiki.archlinux.org/index.php/Co … s_and_code

To print 43°C you would need to process the output of /sys/class/... rather than just cat it. Awk can do this in one pass, or you could use bash's parameter expansion + printf to acheive it.


Moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2018-09-09 01:07:16

Moltke
Member
Registered: 2016-07-12
Posts: 59

Re: (SOLVED) cpu tem widget in awesome wm

jasonwryan wrote:

Please use code tags, not that godawful highlighting, when pasting to the boards: https://wiki.archlinux.org/index.php/Co … s_and_code

To print 43°C you would need to process the output of /sys/class/... rather than just cat it. Awk can do this in one pass, or you could use bash's parameter expansion + printf to acheive it.


Moving to NC...

Thank you for your answer! smile  Sorry about the highlighting. I did read https://wiki.archlinux.org/index.php/Co … s_and_code before posting and I thought of using code tags but then it seemed to me that highlighting was more appropiate and clearly I was  wrong. I'll fix that.  And for future reference, which situations are more appropiate for using one or the other? Is it the content of the rc.lua file and the likes considered as  console snippets?

Thanks again for taking the time to answer.


Judges have decimated, meanings of our laws, already guilt? something has a flow, wrongly accused, blindly confused, open your eyes, wake up realize!

Offline

#4 2018-09-09 01:57:46

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: (SOLVED) cpu tem widget in awesome wm

Any time you are pasting code. Among other things, the monospace styling makes it much easier to read.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2018-09-09 02:33:27

Moltke
Member
Registered: 2016-07-12
Posts: 59

Re: (SOLVED) cpu tem widget in awesome wm

Ok, I tried

awful.widget.watch([[bash -c "cat/sys/class/hwmon/hwmon0/device/temp1_input| awk '{print $1/1000 \"°C\"}'"]], 15),

but no values are shown. what am I doing wrong?


Judges have decimated, meanings of our laws, already guilt? something has a flow, wrongly accused, blindly confused, open your eyes, wake up realize!

Offline

#6 2018-09-09 02:45:14

circleface
Member
Registered: 2012-05-26
Posts: 639

Re: (SOLVED) cpu tem widget in awesome wm

I'm no programmer, but you need a space between cat and /sys/class/hwmon/hwmon0/device/temp1_input| awk '{print $1/1000 \"°C\"}'"]], 15),

Offline

#7 2018-09-09 02:58:48

Moltke
Member
Registered: 2016-07-12
Posts: 59

Re: (SOLVED) cpu tem widget in awesome wm

circleface wrote:

I'm no programmer, but you need a space between cat and /sys/class/hwmon/hwmon0/device/temp1_input| awk '{print $1/1000 \"°C\"}'"]], 15),

Space or no space is the same resullt; no values are shown. And I did use space but when pasting here it seems I did it wrong. Thanks for your answer!


Judges have decimated, meanings of our laws, already guilt? something has a flow, wrongly accused, blindly confused, open your eyes, wake up realize!

Offline

#8 2018-09-09 03:37:24

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,541
Website

Re: (SOLVED) cpu tem widget in awesome wm

Not only is there a useless use of cat, but also a useless use of bash:

awful.widget.watch('awk "{print $1/1000 \"°C\";}" /sys/class/hwmon/hwmon0/device/temp1_input', 15),

You also seem to have switched out the single quote of the command string to double square brackets.  I don't know much lua, but I'm pretty sure that'd not be acceptable.

FWIW, you could also consider sed which would simplify the nested quotes a bit though it would just floor the value rather than round:

awful.widget.watch('sed "s/\(..\).*/\1°C/" /sys/class/hwmon/hwmon0/device/temp1_input', 15),

Last edited by Trilby (2018-09-09 03:40:30)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#9 2018-09-09 03:50:50

Moltke
Member
Registered: 2016-07-12
Posts: 59

Re: (SOLVED) cpu tem widget in awesome wm

Trilby wrote:

Not only is there a useless use of cat, but also a useless use of bash:

awful.widget.watch('awk "{print $1/1000 \"°C\";}" /sys/class/hwmon/hwmon0/device/temp1_input', 15),

You also seem to have switched out the single quote of the command string to double square brackets.  I don't know much lua, but I'm pretty sure that'd not be acceptable.

FWIW, you could also consider sed which would simplify the nested quotes a bit though it would just floor the value rather than round:

awful.widget.watch('sed "s/\(..\).*/\1°C/" /sys/class/hwmon/hwmon0/device/temp1_input', 15),

Thanks for your answer! I tried your suggestion and same result; no temps values are shown. Check here: https://imgur.com/FSvnzyY

Well, to be honest I haven't used awk command that much. Regarding the use of bash I was following instructions from awesome site, I simply changed it a bit to meet my needs. I don't know much if any lua either. I was doing some trial and error.


Judges have decimated, meanings of our laws, already guilt? something has a flow, wrongly accused, blindly confused, open your eyes, wake up realize!

Offline

#10 2018-09-09 04:17:28

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,541
Website

Re: (SOLVED) cpu tem widget in awesome wm

And do the awk or sed commands work on their own in a terminal?


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#11 2018-09-09 05:05:22

Moltke
Member
Registered: 2016-07-12
Posts: 59

Re: (SOLVED) cpu tem widget in awesome wm

Trilby wrote:

And do the awk or sed commands work on their own in a terminal?

Awk didn't while sed did but return an error in rc.lua file, something about some wrong sequence. However, I found a solution. I was also posting in another site and they gave it to me:

awful.widget.watch('bash -c "cat /sys/class/hwmon/hwmon0/device/temp1_input"', 15, 
  function(widget, s) widget:set_text(("%d°C"):format(tonumber(s)/1000)) end),

This works as I wanted it to. Check it here: https://imgur.com/oL4OS0T

EDIT: In order to get the "°C", like 43°C, I needed to add ("%d°C"):format.

Last edited by Moltke (2018-09-10 18:33:31)


Judges have decimated, meanings of our laws, already guilt? something has a flow, wrongly accused, blindly confused, open your eyes, wake up realize!

Offline

Board footer

Powered by FluxBB