[SOLVED] Terminal Command Works But Error When Done within Conky

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Jator
Level 2
Level 2
Posts: 80
Joined: Sat Mar 13, 2021 10:58 am

[SOLVED] Terminal Command Works But Error When Done within Conky

Post by Jator »

Trying to finish up a Conky config file and having an issue. WHen I use the following code within a terminal box, it runs fine:

Code: Select all

cat /home/jay/.conky/wget/192.168.0.2/stats/h5/index.html | grep -A11 'Key Rate' | tail -1 | sed -r 's/^[[:space:]]*([^[:space:]]*).*$/\1/'
But when I try and convert it in a Conky script:

Code: Select all

${goto 10}${font}${color} - ${execi 20 cat /home/jay/.conky/wget/192.168.0.2/stats/h5/index.html | grep 'Hostname Summary for' | cut -c 33-40}: ${alignr}${execi 20 cat /home/jay/.conky/wget/192.168.0.2/stats/h5/index.html | grep -A11 'Key Rate' | tail -1 | sed -r 's/^[[:space:]]*([^[:space:]]*).*$/\1/'}
I get the following error with Conky:

Code: Select all

conky: Syntax error (/home/jay/.conkyrc:260: nesting of [[...]] is deprecated near '[') while reading config file. 
conky: Assuming it's in old syntax and attempting conversion.
conky: [string "..."]:139: attempt to index local 'settings' (a nil value)
I even tried dumping the offending programing into a script to be called by Conky outside of the ./conky file, but had no luck with that:

Code: Select all

#!/bin/sh

\${execi 20 cat /home/jay/.conky/wget/192.168.0.2/stats/h5/index.html | grep -A11 'Key Rate' | tail -1 | sed -r 's/^[[:space:]]*([^[:space:]]*).*$/\1/'}
Any advice on what I am doing wrong?

TIA
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
AndyMH
Level 21
Level 21
Posts: 13704
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Terminal Command Works But Error When Done within Conky

Post by AndyMH »

Put

Code: Select all

cat /home/jay/.conky/wget/192.168.0.2/stats/h5/index.html | grep -A11 'Key Rate' | tail -1 | sed -r 's/^[[:space:]]*([^[:space:]]*).*$/\1/'
into a one line script (okay two lines)

Code: Select all

#!/usr/bin/bash
cat /home/jay/.conky/wget/192.168.0.2/stats/h5/index.html | grep -A11 'Key Rate' | tail -1 | sed -r 's/^[[:space:]]*([^[:space:]]*).*$/\1/'
save it somewhere, make it executable and in conky

Code: Select all

${goto 10}${font}${color} - ${execi 20 /fullpathname_to_myscript}
Looks like you are pulling a file off a local device on your LAN and saving to a file, you should be able to do that in your script as well.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
Jator
Level 2
Level 2
Posts: 80
Joined: Sat Mar 13, 2021 10:58 am

Re: Terminal Command Works But Error When Done within Conky

Post by Jator »

Thanks, that worked. I'll see if I can compare the 2 and figure out where I went astray. ;)
User avatar
zcot
Level 9
Level 9
Posts: 2832
Joined: Wed Oct 19, 2016 6:08 pm

Re: [SOLVED] Terminal Command Works But Error When Done within Conky

Post by zcot »

The original problem is that conky isn't able to parse the sed marking([[) in that second $execi block. It does have to parse the input in the $execi section and it's getting hung up on the [[ thinking that you are trying to implement a conky template instead.

But really, anything more than a simple call or two should probably just be put in a script anyway as AndyMH mentions. It makes the conky config more readable, easier to parse anything too complex, and it's not really different performance-wise.

The reason that sample script attempt didn't work is because you can't put conky markup in a shell script. The shell doesn't understand $execi or $alignr or any conky markup like that. It's just strictly stuff you would do with terminal.
Locked

Return to “Scripts & Bash”