LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   customizing the statusbar dwmblock (DWM - Tiling Window Manager) (https://www.linuxquestions.org/questions/linux-desktop-74/customizing-the-statusbar-dwmblock-dwm-tiling-window-manager-4175676690/)

apoorv569 06-08-2020 03:14 AM

customizing the statusbar dwmblock (DWM - Tiling Window Manager)
 
i need some help with customizing my DWM bar, im using dwmblocks, i want to know the commands to get the specific output to show on my status bar.

what command gives me -

1. CPU USAGE % actual usage not load average, like (9% 99% 100%) no decimal value or text.

2. RAM USAGE % actual ram usage same as cpu without decimal value or text.

3. command for detecting when the webcam is in use and displays 🎥 or something else, only when webcam is being used no text just emoticon or unicode, when not is use nothing shows

4. command for detecting when the microphone is in use and displays 🎙️ or something else same as webcam, only when being used else nothing shows

5. command for detecting when a usb drive is connected and shows a  or something, only when a usb device is connected, else nothing shows

6. command for bluetooth that shows  always in status bar but changes to  when a device is connected to bluetooth

7. command that gets download and upload internet speeds in megabytes per second

EDIT : i edited the post and title to add clarification and avoid confusion.

shruggy 06-08-2020 12:02 PM

For #1 and #2 you probably should have a look at info in the /proc pseudo-filesystem, specifically at /proc/stat and /proc/meminfo.

TB0ne 06-08-2020 12:11 PM

Quote:

Originally Posted by apoorv569 (Post 6131972)
i need some help with writing some scripts to show on my status bar. i need a script that shows

1. CPU USAGE % actual usage not load average, like (9% 99% 100%) no decimal value or text, most scripts i found shows decimal value like 9.9%.
2. RAM USAGE % actual ram usage same as cpu without decimal value or text.
3. a script for webcam that displays 🎥 or something else, only when webcam is being used no text just emoticon or unicode, when not is use nothing shows
4. a script for microphone that displays 🎙️ or something else same as webcam, only when being used else nothing shows
5. a script for usb that shows a  or something, only when a usb device is connected else nothing shows
6. a script for bluetooth that shows  always in status bar but changes to  when a device is connected to bluetooth
7. a script that shows download and upload internet speeds in megabytes per second

somewhere i found that script has to be like this
Code:

#!/bin/sh
case $BLOCK_BUTTON in
    1) #left click action here
        ;;
    2) #  middle click action here
        ;;
    3) # right click action here
        ;;
esac
#normal block commands here

button actions should be pretty normal like left click to open related app for middle and right click i can't think of something.

Ok...so show us what you've done/tried/written so far, and tell us where you're stuck. Read the "Question Guidelines" link in my posting signature...we are happy to help you, but we will NOT write your script/do your work for you.

Post your efforts, and tell us where you're stuck, and what error(s)/message(s) you're getting, and we will be happy to assist. Otherwise, there are MANY bash tutorials you can find with a brief search to help you get started.

apoorv569 06-08-2020 04:58 PM

Quote:

Originally Posted by TB0ne (Post 6132109)
Ok...so show us what you've done/tried/written so far, and tell us where you're stuck. Read the "Question Guidelines" link in my posting signature...we are happy to help you, but we will NOT write your script/do your work for you.

Post your efforts, and tell us where you're stuck, and what error(s)/message(s) you're getting, and we will be happy to assist. Otherwise, there are MANY bash tutorials you can find with a brief search to help you get started.

for cpu and ram i found this on the internet for cpu -
Code:

top -bn1 | grep load | awk '{printf "%.2f%%\t\t\n", $(NF-2)}'
and for ram -
Code:

free -m | awk 'NR==2{printf "%.2f%%\t\t", $3*100/$2 }
but it shows decimal value like 9.99% i dont want decimal value. and also for cpu it shows load average value not exact cpu usage %

for netspeed im using someone else's script i found here but it shows value in kilobits i want in kilobytes and in 9.99% format decimal value with only 2 digits after decimal

and for other other stuff like webcam i found this script here i did not put this on my statusbar yet i ran this in the terminal to see what output it gives. so its always visible i guess and changes to rec or off accordingly. which i don't want i want to show only icon when in use no text and hide when not in use.

for microphone usb and bluetooth i didn't find anything yet.

TB0ne 06-08-2020 05:57 PM

Quote:

Originally Posted by apoorv569 (Post 6132216)
for cpu and ram i found this on the internet for cpu -
Code:

top -bn1 | grep load | awk '{printf "%.2f%%\t\t\n", $(NF-2)}'
and for ram -
Code:

free -m | awk 'NR==2{printf "%.2f%%\t\t", $3*100/$2 }
but it shows decimal value like 9.99% i dont want decimal value. and also for cpu it shows load average value not exact cpu usage %

for netspeed im using someone else's script i found here but it shows value in kilobits i want in kilobytes and in 9.99% format decimal value with only 2 digits after decimal

and for other other stuff like webcam i found this script here i did not put this on my statusbar yet i ran this in the terminal to see what output it gives. so its always visible i guess and changes to rec or off accordingly. which i don't want i want to show only icon when in use no text and hide when not in use.

for microphone usb and bluetooth i didn't find anything yet.

Ok, so again: **SHOW US WHAT YOU HAVE DONE**

You're telling us commands, and what you DON'T want...what steps have you taken to get what you DO want?? Have you read the man pages on the command(s) you posted? Read up on printf and how to modify the output? Done/tried ANYTHING? And you posted links to other scripts...what modifications have you made to change them?? Again, we aren't going to modify other peoples scripts for you, anymore than we would write them for you. You need to show us YOUR efforts.

apoorv569 06-08-2020 09:12 PM

Quote:

Originally Posted by TB0ne (Post 6132233)
Ok, so again: **SHOW US WHAT YOU HAVE DONE**

You're telling us commands, and what you DON'T want...what steps have you taken to get what you DO want?? Have you read the man pages on the command(s) you posted? Read up on printf and how to modify the output? Done/tried ANYTHING? And you posted links to other scripts...what modifications have you made to change them?? Again, we aren't going to modify other peoples scripts for you, anymore than we would write them for you. You need to show us YOUR efforts.

if i knew the steps required to change, modify or write a command in the first place i would not be putting the question i posted in the way that i did. i already told what i tried, that is using other people's script. if you think my question is not something YOU can help with i suggest avoiding this post and stop replying.

and im not looking for anyone to write down scripts for me, im looking for the commands that can get the me the specific output that im looking for.

i have already edited the OP for much more clarification

TB0ne 06-09-2020 08:18 AM

Quote:

Originally Posted by apoorv569 (Post 6132267)
if i knew the steps required to change, modify or write a command in the first place i would not be putting the question i posted in the way that i did. i already told what i tried, that is using other people's script. if you think my question is not something YOU can help with i suggest avoiding this post and stop replying.

and im not looking for anyone to write down scripts for me, im looking for the commands that can get the me the specific output that im looking for. i have already edited the OP for much more clarification

I can absolutely write such scripts, and will be happy to help you with yours.

**AGAIN** Posting a list of things you looked up somewhere and saying "I want this instead", isn't effort on your part. You're taking something from someone else and asking US to modify it FOR YOU. You have provided no more clarification, as all you've done is re-state your question, and tell us (again) what you don't want...still not seeing where you've attempted to make any changes to what you were given, despite being given hints as to what to look at.

**AGAIN** You were told to read the man pages, and directed to scripting tutorials, which are both easy to find. That is where you begin to 'know the steps'. Look at the commands; run them in pieces, and see how you can modify the output; experiment and learn. Don't just hand us things you've found and expect us to do it for you.

apoorv569 06-10-2020 01:56 PM

Quote:

Originally Posted by TB0ne (Post 6132423)
I can absolutely write such scripts, and will be happy to help you with yours.

**AGAIN** Posting a list of things you looked up somewhere and saying "I want this instead", isn't effort on your part. You're taking something from someone else and asking US to modify it FOR YOU. You have provided no more clarification, as all you've done is re-state your question, and tell us (again) what you don't want...still not seeing where you've attempted to make any changes to what you were given, despite being given hints as to what to look at.

**AGAIN** You were told to read the man pages, and directed to scripting tutorials, which are both easy to find. That is where you begin to 'know the steps'. Look at the commands; run them in pieces, and see how you can modify the output; experiment and learn. Don't just hand us things you've found and expect us to do it for you.

ok so i have come with this (these are not the entire scripts these are just the commands that im getting info from)

for cpu i did
Code:

top -bn 1 | awk '/^%Cpu/ {print int($2 + $4 + $6)" %"}'
for memory i did
Code:

free -h | awk '/^Mem: /{ print $3 }'
which shows me used memory rather than percentage, but after looking at it im fine with it. if there is a way to get percentage that would be nice.

for webcam i did
Code:


if [[ "$(fuser /dev/video0)" != "" ]]; then
      icon=""
    else
      icon=""
    fi
 
  printf "%s%s\\n" "$icon"

for bluetooth i did
Code:

if [[ "$(bluetoothctl info)" != "Missing device address argument" ]]; then
      icon=""
    else
      icon=""
    fi
 
  printf "%s%s\\n" "$icon"

i could not find any tool or way for usb or microphone to extract data from.

what do you think?

shruggy 06-10-2020 06:56 PM

Quote:

Originally Posted by apoorv569 (Post 6132851)
for cpu i did
Code:

top -bn 1 | awk '/^%Cpu/ {print int($2 + $4 + $6)" %"}'

I'm not sure that rounding toward zero (int) is what you really want. I'd use printf "%.f%%\n", $2+$4+$6 instead.

Quote:

Originally Posted by apoorv569 (Post 6132851)
for memory i did
Code:

free -h | awk '/^Mem: /{ print $3 }'

Again, you probably want to know amount of actually available memory which is the last field. I'd use print $NF here.

apoorv569 06-10-2020 09:53 PM

Quote:

Originally Posted by shruggy (Post 6132906)
I'm not sure that rounding toward zero (int) is what you really want. I'd use printf "%.f%%\n", $2+$4+$6 instead.


Again, you probably want to know amount of actually available memory which is the last field. I'd use print $NF here.

can you please explain what does printf "%.f%%\n" do.

and i want to see either total used ram percentage or used memory in Mib or Gib. not available memory.

shruggy 06-11-2020 05:27 AM

Quote:

Originally Posted by apoorv569 (Post 6132935)
can you please explain what does printf "%.f%%\n" do.

The dot after the first % stands for precision. f is a conversion specifier for floating-point numbers. The second % needs to be doubled to be taken literally as the percent sign. From the printf(3) manual page:
Quote:

If the precision is given as just '.', the precision is taken to be zero.
Quote:

f, F
The double argument is rounded and converted to decimal notation in the style [-]ddd.ddd, where the number of digits after the decimal-point character is equal to the precision specification. If the precision is missing, it is taken as 6; if the precision is explicitly zero, no decimal-point character appears. If a decimal point appears, at least one digit appears before it.


TB0ne 06-11-2020 08:22 AM

Quote:

Originally Posted by apoorv569 (Post 6132851)
ok so i have come with this (these are not the entire scripts these are just the commands that im getting info from)
for cpu i did
Code:

top -bn 1 | awk '/^%Cpu/ {print int($2 + $4 + $6)" %"}'
for memory i did
Code:

free -h | awk '/^Mem: /{ print $3 }'
which shows me used memory rather than percentage, but after looking at it im fine with it. if there is a way to get percentage that would be nice. for webcam i did
Code:

if [[ "$(fuser /dev/video0)" != "" ]]; then
      icon=""
    else
      icon=""
    fi
 
  printf "%s%s\\n" "$icon"

for bluetooth i did
Code:

if [[ "$(bluetoothctl info)" != "Missing device address argument" ]]; then
      icon=""
    else
      icon=""
    fi
    printf "%s%s\\n" "$icon"

i could not find any tool or way for usb or microphone to extract data from. what do you think?

Thank you for showing your efforts. Not sure if you'll be able to do anything regarding the microphone, but you can try to use the fuser command on the devices in /dev/snd, to see if you get output then. For USB you could try running a tail on dmesg or your system logs, to see if any new devices are plugged in.

And regarding what printf does...again, did you try to look this up??
https://www.man7.org/linux/man-pages/man3/printf.3.html
https://www.geeksforgeeks.org/printf...with-examples/

apoorv569 06-11-2020 10:34 AM

Quote:

Originally Posted by TB0ne (Post 6133087)
Thank you for showing your efforts. Not sure if you'll be able to do anything regarding the microphone, but you can try to use the fuser command on the devices in /dev/snd, to see if you get output then. For USB you could try running a tail on dmesg or your system logs, to see if any new devices are plugged in.

And regarding what printf does...again, did you try to look this up??
https://www.man7.org/linux/man-pages/man3/printf.3.html
https://www.geeksforgeeks.org/printf...with-examples/

if do tail on dmesg when i connect a usb drive
Code:

dmesg -S | tail                                                                                                   
[29356.161600] usb-storage 1-3:1.0: USB Mass Storage device detected
[29356.165327] scsi host2: usb-storage 1-3:1.0
[29357.177594] scsi 2:0:0:0: Direct-Access    MBIL SSM Moser Baer Disk  8.07 PQ: 0 ANSI: 4
[29357.177884] sd 2:0:0:0: Attached scsi generic sg2 type 0
[29357.178529] sd 2:0:0:0: [sdb] 31027200 512-byte logical blocks: (15.9 GB/14.8 GiB)
[29357.179225] sd 2:0:0:0: [sdb] Write Protect is off
[29357.179228] sd 2:0:0:0: [sdb] Mode Sense: 23 00 00 00
[29357.179923] sd 2:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[29357.960971]  sdb: sdb1 sdb2 sdb3
[29357.963639] sd 2:0:0:0: [sdb] Attached SCSI removable disk

and then i grep something that i could use
Code:

dmesg -S | tail | grep "usb-storage"                                                                       
[28987.177058] usb-storage 1-3:1.0: USB Mass Storage device detected
[28987.180614] scsi host2: usb-storage 1-3:1.0

i made this script
Code:

if [[ "$(dmesg -S | tail | grep "usb-storage")" == "USB Mass Storage device detected"]]; then
          icon=" ��️ "
          else
          icon=""
  fi
 
  printf "%s%s\\n" "$icon"

but it give me this error
Code:

./usb: line 3: syntax error in conditional expression: unexpected token `;'
./usb: line 3: syntax error near `;'
./usb: line 3: `if [[ "$(dmesg -S | tail | grep "usb-storage")" == "USB Mass Storage device detected"]]; then'

sorry, if this is wrong, im learning. but i want to learn this seems interesting.

for microphone "fuser /dev/snd" does nothing. but "fuser /dev/snd/controlC0" gives me this when mic is not in use
Code:

fuser /dev/snd/controlC0                                                                                         
/dev/snd/controlC0:  1074

when in use it gives me
Code:

fuser /dev/snd/controlC0                                                                                         
/dev/snd/controlC0:  1074 376860

also "fuser /dev/snd/pcmC1D0c" when mic is not in use gives nothing. but when in use it gives
Code:

fuser /dev/snd/pcmC1D0c
/dev/snd/pcmC1D0c:    1074m


shruggy 06-11-2020 10:45 AM

Quote:

Originally Posted by apoorv569 (Post 6133131)
Code:

if [[ "$(dmesg -S | tail | grep "usb-storage")" == "USB Mass Storage device detected"]]

Put a space bethween " and ]]. I'd probably just test for presence of the string:
Code:

if dmesg -S|grep -q "USB Mass Storage device detected"; then

TB0ne 06-11-2020 10:48 AM

Quote:

Originally Posted by apoorv569 (Post 6133131)
if do tail on dmesg when i connect a usb drive
Code:

dmesg -S | tail                                                                                                   
[29356.161600] usb-storage 1-3:1.0: USB Mass Storage device detected
[29356.165327] scsi host2: usb-storage 1-3:1.0
[29357.177594] scsi 2:0:0:0: Direct-Access    MBIL SSM Moser Baer Disk  8.07 PQ: 0 ANSI: 4
[29357.177884] sd 2:0:0:0: Attached scsi generic sg2 type 0
[29357.178529] sd 2:0:0:0: [sdb] 31027200 512-byte logical blocks: (15.9 GB/14.8 GiB)
[29357.179225] sd 2:0:0:0: [sdb] Write Protect is off
[29357.179228] sd 2:0:0:0: [sdb] Mode Sense: 23 00 00 00
[29357.179923] sd 2:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[29357.960971]  sdb: sdb1 sdb2 sdb3
[29357.963639] sd 2:0:0:0: [sdb] Attached SCSI removable disk

and then i grep something that i could use
Code:

dmesg -S | tail | grep "usb-storage"                                                                       
[28987.177058] usb-storage 1-3:1.0: USB Mass Storage device detected
[28987.180614] scsi host2: usb-storage 1-3:1.0

i made this script
Code:

if [[ "$(dmesg -S | tail | grep "usb-storage")" == "USB Mass Storage device detected"]]; then
          icon=" ��️ "
          else
          icon=""
  fi
 
  printf "%s%s\\n" "$icon"

but it give me this error
Code:

./usb: line 3: syntax error in conditional expression: unexpected token `;'
./usb: line 3: syntax error near `;'
./usb: line 3: `if [[ "$(dmesg -S | tail | grep "usb-storage")" == "USB Mass Storage device detected"]]; then'

sorry, if this is wrong, im learning. but i want to learn this seems interesting.

No worries...as long as you're learning, you'll keep getting better. You're missing a space after the detected" and before the ]]. That should get rid of that message. And after thinking about it for a bit, try this instead:
Code:

if [[ "$(dmesg -S | tail | grep "usb-storage")" =~ "USB Mass Storage device detected" ]]; then
          icon=" ��️ "
          else
          icon=""
  fi
 
  printf "%s%s\\n" "$icon"

...which will check for the presence of the string in what you get. That way, you can modify this to do different things if you plug in a mouse or some other USB device.
Quote:

for microphone "fuser /dev/snd" does nothing. but "fuser /dev/snd/controlC0" gives me this when mic is not in use
Code:

fuser /dev/snd/controlC0                                                                                         
/dev/snd/controlC0:  1074

when in use it gives me
Code:

fuser /dev/snd/controlC0                                                                                         
/dev/snd/controlC0:  1074 376860

also "fuser /dev/snd/pcmC1D0c" when mic is not in use gives nothing. but when in use it gives
Code:

fuser /dev/snd/pcmC1D0c
/dev/snd/pcmC1D0c:    1074m


So that's the device you need to query with fuser.../dev/snd/pcmC1D0c, and incorporate that into your script.


All times are GMT -5. The time now is 07:20 PM.