LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 06-08-2020, 03:14 AM   #1
apoorv569
Member
 
Registered: Jun 2020
Distribution: Arch Linux
Posts: 61

Rep: Reputation: 0
Post 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.

Last edited by apoorv569; 06-08-2020 at 04:43 PM.
 
Old 06-08-2020, 12:02 PM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

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

Last edited by shruggy; 06-10-2020 at 06:11 PM.
 
Old 06-08-2020, 12:11 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by apoorv569 View Post
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.
 
Old 06-08-2020, 04:58 PM   #4
apoorv569
Member
 
Registered: Jun 2020
Distribution: Arch Linux
Posts: 61

Original Poster
Rep: Reputation: 0
Post

Quote:
Originally Posted by TB0ne View Post
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.
 
Old 06-08-2020, 05:57 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by apoorv569 View Post
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.
 
Old 06-08-2020, 09:12 PM   #6
apoorv569
Member
 
Registered: Jun 2020
Distribution: Arch Linux
Posts: 61

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by TB0ne View Post
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

Last edited by apoorv569; 06-08-2020 at 09:15 PM.
 
Old 06-09-2020, 08:18 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by apoorv569 View Post
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.
 
Old 06-10-2020, 01:56 PM   #8
apoorv569
Member
 
Registered: Jun 2020
Distribution: Arch Linux
Posts: 61

Original Poster
Rep: Reputation: 0
Post

Quote:
Originally Posted by TB0ne View Post
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?

Last edited by apoorv569; 06-10-2020 at 01:59 PM.
 
Old 06-10-2020, 06:56 PM   #9
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
Quote:
Originally Posted by apoorv569 View Post
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 View Post
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.
 
Old 06-10-2020, 09:53 PM   #10
apoorv569
Member
 
Registered: Jun 2020
Distribution: Arch Linux
Posts: 61

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by shruggy View Post
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.
 
Old 06-11-2020, 05:27 AM   #11
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
Quote:
Originally Posted by apoorv569 View Post
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.
 
Old 06-11-2020, 08:22 AM   #12
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by apoorv569 View Post
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/
 
Old 06-11-2020, 10:34 AM   #13
apoorv569
Member
 
Registered: Jun 2020
Distribution: Arch Linux
Posts: 61

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by TB0ne View Post
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

Last edited by apoorv569; 06-11-2020 at 10:43 AM.
 
Old 06-11-2020, 10:45 AM   #14
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
Quote:
Originally Posted by apoorv569 View Post
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

Last edited by shruggy; 06-11-2020 at 10:47 AM.
 
Old 06-11-2020, 10:48 AM   #15
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by apoorv569 View Post
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.

Last edited by TB0ne; 06-11-2020 at 11:00 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: dwm: A Minimalist Tiling Window Manager For Linux LXer Syndicated Linux News 0 04-03-2018 02:52 PM
LXer: Top 4 reasons I use dwm for my Linux window manager LXer Syndicated Linux News 0 07-19-2017 04:40 AM
dwm window manager: conky eats 100%CPU when it has its own window (window_type normal) ondoho Linux - Software 0 10-11-2016 08:49 PM
Get window size with tiling window manager in SDL Snark1994 Programming 1 02-24-2013 08:46 PM
Config-file for DWM window manager on Debian. tirka Linux - Newbie 1 06-25-2011 06:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 10:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration