[SOLVED] Bash script output to conky different then output to terminal

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Post Reply
User avatar
Koentje
Level 6
Level 6
Posts: 1402
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

[SOLVED] Bash script output to conky different then output to terminal

Post by Koentje »

I have a bash script that outputs some headset info to conky. On the terminal it outputs all data i request, but when executed in conky, it output some of the data. And i don't understand why?

Bash script:

Code: Select all

#!/bin/bash

   # Get macadress of headphone
   btmac=$(bluetoothctl devices | grep "^Device E7" | awk '{print $2}')
   echo "$btmac"

   # Is device paired
   btpair=$(echo "$btmac" | while read uuid; do bluetoothctl info $uuid; done | grep "Paired" | awk -F": " '{print "Paired: "$2}')
   echo "$btpair"

   # Is device connected
   btconn=$(echo "$btmac" | while read uuid; do bluetoothctl info $uuid; done | grep "Connected" | awk -F": " '{print "Connected: "$2}')
   echo "$btconn"

   # Battery status
   btbatt=$(bluetooth_battery "$btmac" | awk '{print $1": "$6}')
   echo "$btbatt"

   btbattbar=$(echo "$btbatt" | awk '{print $2}'); btbattbar=${btbattbar:0:-1}
   echo "$btbattbar"

Terminal output:

Code: Select all

E7:D6:AA:76:A3:10
Paired: yes
Connected: yes
Battery: 100%
100

When i start it inside conky the battery stats are not shown... (last 2 lines)
Last edited by Koentje on Tue Nov 28, 2023 5:42 am, edited 1 time in total.
User avatar
Bleys
Level 4
Level 4
Posts: 409
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: Bash script output to conky different then output to terminal

Post by Bleys »

The most important information is missing: What does the Conky command look like?
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Koentje
Level 6
Level 6
Posts: 1402
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Bash script output to conky different then output to terminal

Post by Koentje »

Not really important because it's pretty standard. ${execp ./bt-headset.sh}.
The bash script does run, only the last 2 commands in the script do not output anything for some reason i don't understand. (the bluetooth_battery part)
User avatar
Bleys
Level 4
Level 4
Posts: 409
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: Bash script output to conky different then output to terminal

Post by Bleys »

Koentje wrote: Mon Nov 27, 2023 8:58 pm Not really important because it's pretty standard. ${execp ./bt-headset.sh}.
The bash script does run, only the last 2 commands in the script do not output anything for some reason i don't understand. (the bluetooth_battery part)
Change to ${exec ./bt-headset.sh}.

Description execp:
This differs from $exec in that it parses the output of the command, so you can insert things like ${color red}hi!${color} in your script and have it correctly parsed by Conky. Caveats: Conky parses and evaluates the output of $execp every time Conky loops, and then destroys all the objects. If you try to use anything like $execi within an $execp statement, it will functionally run at the same interval that the $execp statement runs, as it is created and destroyed at every interval.
You do not have any Conky commands in your script. However, it contains some code that could possibly be interpreted as such by execp.
Last edited by Bleys on Tue Nov 28, 2023 4:45 am, edited 1 time in total.
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Koentje
Level 6
Level 6
Posts: 1402
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Bash script output to conky different then output to terminal

Post by Koentje »

Why? Without the p it does not paste the output of the bash script into conky...
The problem is not the execution of the bash script, because it does. The problem is that it does not execute or output the last 2 commands from the bash script. Also no errors...
User avatar
Koentje
Level 6
Level 6
Posts: 1402
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Bash script output to conky different then output to terminal

Post by Koentje »

Bleys wrote: Tue Nov 28, 2023 4:41 am You do not have any Conky commands in your script. However, it contains some code that could possibly be interpreted as such by execp.
I simplified the script for this topic, but it is a part of another bash script that DO have conky objects in them!
I can post all that, but it will only make finding a solution to my problem harder! I already tracked the problem down to this part of the script!
And show me what part of this script could be confused to have conky objects in them? A conky object in a bash script is \${....}. I don't see any backslash in my script followed by a string variable or any of that kind?
User avatar
Koentje
Level 6
Level 6
Posts: 1402
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Bash script output to conky different then output to terminal

Post by Koentje »

Never mind, i solved it. For some reason bluetooth_battery could not be found when started from conky. Even when the folder is in the $PATH... strange..
But solved it by setting the full path to it.
User avatar
Bleys
Level 4
Level 4
Posts: 409
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: [SOLVED] Bash script output to conky different then output to terminal

Post by Bleys »

Do you get error messages when you start conky in the terminal?
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Koentje
Level 6
Level 6
Posts: 1402
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: [SOLVED] Bash script output to conky different then output to terminal

Post by Koentje »

I started my existing conky script on the terminal and i got a warning that it could not find bluetooth_battery. So i created a new conky script and my bash script worked in the new conky!
I then executed ${exec echo "$PATH"} in both and they gave me different paths.. Ok... :roll:
Why i have no clue, but in the new conky the correct folder was in the path, in my existing conky it was not.
User avatar
Bleys
Level 4
Level 4
Posts: 409
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: [SOLVED] Bash script output to conky different then output to terminal

Post by Bleys »

I get the battery even without the Python script via bluetoothctl:

Code: Select all

$ bluetoothctl info
Device EB:06:EF:40:64:AE (public)
	Name: Mpow H7
	Alias: Mpow H7
	Class: 0x00240404
	Icon: audio-headset
	Paired: yes
	Trusted: yes
	Blocked: no
	Connected: yes
	LegacyPairing: no
	UUID: Headset                   (00001108-0000-1000-8000-00805f9b34fb)
	UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
	UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
	UUID: Advanced Audio Distribu.. (0000110d-0000-1000-8000-00805f9b34fb)
	UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
	UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
	Battery Percentage: 0x5E (94)

Would be an alternative
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Koentje
Level 6
Level 6
Posts: 1402
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: [SOLVED] Bash script output to conky different then output to terminal

Post by Koentje »

I'm not, that's why the python script..

Code: Select all

$ bluetoothctl info
Device E7:D6:AA:76:A3:10 (public)
	Name: siindoo-H1
	Alias: siindoo-H1
	Class: 0x00240404
	Icon: audio-card
	Paired: yes
	Trusted: yes
	Blocked: no
	Connected: yes
	LegacyPairing: no
	UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
	UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
	UUID: Advanced Audio Distribu.. (0000110d-0000-1000-8000-00805f9b34fb)
	UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
	UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
	UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
	Modalias: bluetooth:v05D6p000Ad0240
User avatar
Bleys
Level 4
Level 4
Posts: 409
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: [SOLVED] Bash script output to conky different then output to terminal

Post by Bleys »

Code: Select all

sudo nano /etc/bluetooth/main.conf
add to [General]:

Code: Select all

Experimental = true
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Koentje
Level 6
Level 6
Posts: 1402
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: [SOLVED] Bash script output to conky different then output to terminal

Post by Koentje »

Already done that and other tricks.. this chinese headset does not give the battery status without the python script!
Post Reply

Return to “Compiz, Conky, Docks & Widgets”