You are not logged in.

#1 2017-12-20 20:35:52

kes
Member
Registered: 2017-12-12
Posts: 35

[SOLVED] Conky - BASH Command substitution

I am using Conky to display some MQTT output.

The constituent parts of the below code work just fine, however the BASH command substitution does not.

This part works fine as expected, returning the MQTT value for the topic:

Living rm    ${texeci 60 mosquitto_sub -C 1 -h 151.101.128.81 -t house/groundfloor/livingroom/temperature_DS18B20}

And this part, the BASH command works as expected, producing an IP address, when used in the   terminal command prompt

echo $(ping -c1 my.home.ip.co.uk | grep -oE -m 1 "[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}")

However when I substitute the BASH command for the IP address, into the conky command I get this and it does not work:

Living rm    ${texeci 60 mosquitto_sub -C 1 -h echo $(ping -c1 my.home.ip.co.uk | grep -oE -m 1 "[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}") -t house/groundfloor/livingroom/temperature_DS18B20}

I have tried many and various permutations of wrapping the BASH command in things like

${exec ...}
${texeci 60  ...}

etc
with no sucess.

I have also placed the BASH command in a .sh file and called the file with /path/to/file.sh placed in the conky mosquito command which does not work either.

In essence, I am grep'ing my modem router external IP which dynamically changes, then inserting it into the conky mosquitto command.



Any ideas?

Last edited by kes (2017-12-22 13:04:10)

Offline

#2 2017-12-21 07:22:29

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,068
Website

Re: [SOLVED] Conky - BASH Command substitution

kes wrote:

I have also placed the BASH command in a .sh file and called the file with /path/to/file.sh placed in the conky mosquito command which does not work either

That method should work, did you make the script executable?

Offline

#3 2017-12-21 11:15:55

kes
Member
Registered: 2017-12-12
Posts: 35

Re: [SOLVED] Conky - BASH Command substitution

yes, I did make it executable. The stand alone script works at the command prompt and when I run it I get the expected output

$ /path/to/file.sh
$ 151.101.64.81

When I try

Living rm    ${texeci 60 mosquitto_sub -C 1 -h /path/to/file.sh -t house/groundfloor/livingroom/temperature_DS18B20}

The error the conky command prompt produces in the terminal is

$ conky -c ../linux_config/script_conky/on_desk_widgets_EXTERNAL_ACCESS_TO_MQTT
conky: Syntax error (.../linux_config/script_conky/on_desk_widgets_EXTERNAL_ACCESS_TO_MQTT:1: '=' expected near 'yes') while reading config file. 
conky: Assuming it's in old syntax and attempting conversion.
conky: desktop window (1400261) is subwindow of root window (131)
conky: window type - normal
conky: drawing to created window (0x1a00001)
conky: drawing to double buffer
conky: one or more $endif's are missing
Unable to connect (Lookup error.).


Here is another try and error.

The following line works just fine and gives own external IP at the command prompt

$ dig +short myip.opendns.com @resolver1.opendns.com
$ 151.101.64.81

And here it is substituted into the conky mosquitto_sub command 

Living rm(script) ${texeci 60 mosquitto_sub -C 1 -h dig +short myip.opendns.com @resolver1.opendns.com -t headlands/groundfloor/livingroom/temperature_DS18B20}

and here is the conky output

Error: Unknown option '+short'.

Use 'mosquitto_sub --help' to see usage.
Error: Unknown option '+short'.

Use 'mosquitto_sub --help' to see usage.
Error: Unknown option '+short'.

Use 'mosquitto_sub --help' to see usage.

Last edited by kes (2017-12-21 11:16:50)

Offline

#4 2017-12-21 11:32:29

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,648

Re: [SOLVED] Conky - BASH Command substitution

My idea would be that time is much too short.
Why must the (IP address) temperature be queried after one minute? It doesn't change in a minute.

So I would let conky run the bash script and increase the time.
Like this

...
TEXT
${texeci 1800 bash $HOME/path/to/file.sh}
kes wrote:

The error the conky command prompt produces in the terminal is

This indicates that you are using the wrong syntax. -->conky1.9 or conky1.10   wink

Offline

#5 2017-12-21 13:17:47

kes
Member
Registered: 2017-12-12
Posts: 35

Re: [SOLVED] Conky - BASH Command substitution

This works just fine

${texeci 1800 bash $HOME/path/to/file.sh}

But this substitution does not

Living rm(script) ${texeci 1800 mosquitto_sub -C 1 -h ${texeci 1800 bash $HOME/path/to/file.sh} -t house/groundfloor/livingroom/temperature_DS18B20}

Last edited by kes (2017-12-21 15:27:02)

Offline

#6 2017-12-21 15:02:50

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,648

Re: [SOLVED] Conky - BASH Command substitution

If you designed the script to write the result (the temperature) into your $HOME, then Conky only has to do the following:
If this is the output path of the script

$HOME/headlands/groundfloor/livingroom/temperature_DS18B20

then you need to see what's in the file and prepare it for Conky.
e.g.

TEXT
${texeci 1800 bash $HOME/path/to/file.sh}
${execpi 600 grep $HOME/headlands/groundfloor/livingroom/temperature_DS18B20 | cut -c12-17}

or

${execpi 600 sed -n '2p' $HOME/headlands/groundfloor/livingroom/temperature_DS18B20}

Offline

#7 2017-12-21 15:43:51

kes
Member
Registered: 2017-12-12
Posts: 35

Re: [SOLVED] Conky - BASH Command substitution

I can write the MQTT output to a file and parse the file with grep or sed but I want to do this without file I/O.

Offline

#8 2017-12-21 17:29:59

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,648

Re: [SOLVED] Conky - BASH Command substitution

^ I can't help you with that.  My scripting skills are not enough for this.  :8

Offline

#9 2017-12-21 18:05:41

iMBeCil
WAAAT?
From: Edrychwch o'ch cwmpas
Registered: 2015-09-29
Posts: 767

Re: [SOLVED] Conky - BASH Command substitution

@OP:

This has been working for me (Conky 1.9) some time ago (now I don't use Conky anymore):

{$execi 10 `expr "\`sylpheed --status inbox\`" : '[0-9]* \([0-9]*\)'`}

(nevermind different command, 'sylpheed', instead of 'echo').

However, the important difference, compared to your solution, is that I have the backticks (`) instead of $(...) pair. Therefore, could you please try with bacticks? I somehow suspect that the dollar sign $ for command execution is misinterpreted by conky as its 'command'.

Something like this might work:

Living rm    ${texeci 60 mosquitto_sub -C 1 -h echo `ping -c1 home.ip.co.uk | grep -o ".co.uk ([0-9]\{0,3\}\.[0-9]\{0,3\}\.[0-9]\{0,3\}\.[0-9]\{0,3\}).*$" | grep -o "\([0-9]\{0,3\}\.[0-9]\{0,3\}\.[0-9]\{0,3\}\.[0-9]\{0,3\}\)"` -t house/groundfloor/livingroom/temperature_DS18B20}

(I hope I guessed correctly, where to put backticks `...` instead of $(...)  8)

EDIT1: I'm using execi, and you are using texeci ... I'm too lazy to check the difference ... might this be the culprit?

EDIT2: I have backticks inside backticks ... check if you are missing outside backticks?!

Last edited by iMBeCil (2017-12-21 18:11:40)


Postpone all your duties; if you die, you won't have to do them ..

Offline

#10 2017-12-21 20:45:25

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,648

Re: [SOLVED] Conky - BASH Command substitution

iMBeCil wrote:

EDIT1: I'm using execi, and you are using texeci ... I'm too lazy to check the difference ... might this be the culprit?

^ from my documents for you   wink

$execi// - Interval Command - Executes a shell command at a certain interval, specified in seconds. The value cannot be smaller than the //update_interval// option of Conky.

$execp// - Command - Same as $exec, only with the possibility to decorate output with colors or fonts in the command chains.
//$execpi// - Interval Command - see $execp/$execi

$texeci// - Interval Command - Same as $execi, except that //$texeci// should be used for commands that have a very large time interval.

Offline

#11 2017-12-21 20:48:37

iMBeCil
WAAAT?
From: Edrychwch o'ch cwmpas
Registered: 2015-09-29
Posts: 767

Re: [SOLVED] Conky - BASH Command substitution

big_smile  big_smile Thanks!


Postpone all your duties; if you die, you won't have to do them ..

Offline

#12 2017-12-22 01:20:13

kes
Member
Registered: 2017-12-12
Posts: 35

Re: [SOLVED] Conky - BASH Command substitution

As with many things I do, there's a lot of head scratching.
Then, somehow, like busses, the ideas come along three at once.

I got three solutions.

  It was the backticks that did it !

Thank's for the help guys.

I was beginning to doubt this was possible.

For the BASH command substitution, it was not necessary to use any conky curly brackets pairs ${} as follows, to resolve the ip address for the mosquitto_sub command

${execi 300 bash_ip_resolving_command_here}
${execp 300 bash_ip_resolving_command_here}
${execpi 300 bash_ip_resolving_command_here}
${texeci 300 bash_ip_resolving_command_here}

Nor was it necessary to use any of these

$()

All of the below three solutions worked by wrapping the command in command substitution backticks. The IP address is resolved in each case into the mosquitto_sub command sucessfully.

# cat ip address from text file ip_address
Living rm    ${texeci 300 mosquitto_sub -C 1 -h `cat /path/to/filed/ip_address` -t house/groundfloor/livingroom/temperature_DS18B20} °C

# dynamically resolve modem router ip address
Living rm    ${texeci 300 mosquitto_sub -C 1 -h `dig +short myip.opendns.com @resolver1.opendns.com` -t house/groundfloor/livingroom/temperature_DS18B20} °C

# dynamically resolve modem router ip address
Living rm    ${texeci 300 mosquitto_sub -C 1 -h `ping -c1 my.home.ip.co.uk | grep -oE -m 1 "[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}"` -t house/groundfloor/livingroom/temperature_DS18B20} °C

Now I can see what is going on in the house when I am away.

Many thanks for help  8o

Last edited by kes (2017-12-22 01:28:04)

Offline

#13 2017-12-22 10:33:33

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,648

Re: [SOLVED] Conky - BASH Command substitution

^ Congratulations!
Then please put a[solved] in the subject line of your opening post to make finding easier for other users.   wink

Offline

#14 2017-12-22 12:44:27

iMBeCil
WAAAT?
From: Edrychwch o'ch cwmpas
Registered: 2015-09-29
Posts: 767

Re: [SOLVED] Conky - BASH Command substitution

^^Glad it worked. You're welcome.


Postpone all your duties; if you die, you won't have to do them ..

Offline

Board footer

Powered by FluxBB