Dwm xsetroot processor usage display with awk

I am using dwm tiling window manager on Arch Linux. I want to customize the display of the top bar. I already added the date, memory, now I play and idle time, but the processor display will not work for me. When I try to run the code to display CPU usage in the terminal, it works fine, but it doesn't work when I put it in the top bar. It does not display anything. Here is the code:

while true; do
    xsetroot -name "Memory $(free -m | grep '^Mem' | awk '{print "total: " $2 "MB used: " $3"MB"}') | CPU $(top -n 1 | grep '^Cpu' | tr -d 'usy,' | awk '{print "user " $2 ", sys " $3}') | Uptime: $(uptime | awk '{print $3}' | tr -d ',') | Now playing: $(ncmpcpp --now-playing | tr -d '(:[:digit:])') | $( date +"%F %R" )"
    sleep 20s
done &

The part I'm talking about is after the line "CPU". The code is in my .xinitrc and, as I said, everything works fine, except for the display of the processor.

+3
source share
1 answer

, top -b . . , () :

while true; do
    xsetroot -name "Memory $(free -m | grep '^Mem' | awk '{print "total: " $2 "MB used: " $3"MB"}') | CPU $(top -bn 1 | grep '^Cpu' | tr -d 'usy,' | awk '{print "user " $2 ", sys " $3}') | Uptime: $(uptime | awk '{print $3}' | tr -d ',') | Now playing: $(ncmpcpp --now-playing | tr -d '(:[:digit:])') | $( date +"%F %R" )"
    sleep 20s
done &
+1

Source: https://habr.com/ru/post/1793235/


All Articles