You are not logged in.

#1 2016-03-02 17:44:27

stackoverflow
Member
Registered: 2015-09-23
Posts: 43

problem:run bash script in conky

hi every bode
i have a conky that show my favorite proccess.and i want to show my tor service status with a colorfull font.
this is my conky:
o42n_aaaaaaaa.png
i wrote a script and authorize it to run with chmod+x.
this is my script:

#!/bin/bashlastTorStatus=$(systemctl status tor.service | grep Bootstrap | cut -d" " -f7 | cut -d: -f1 | tail -1 | cut -d% -f1);
if [ "$lastTorStatus" == "100" ];then
		echo "green"
	elif [ "$lastTorStatus" > "50" $$ "$lastTorStatus" < "100" ];then
		echo "yellow";
	else
		echo "red"
fi

and this is my conky.where i call my script:

${voffset 3}${font StyleBats:size=10}${color ${exec ~/.conky/ArchConky/service.sh}}j${voffset -1}${font DroidSans:size=8.65}${color3}${offset 5}tor: ${offset 25}${exec systemctl status tor.service | grep Bootstrap | cut -d" " -f7 | cut -d: -f1 | tail -1}

and this is original conky file:

${voffset 3}${font StyleBats:size=10}${color green}}j${voffset -1}${font DroidSans:size=8.65}${color3}${offset 5}tor: ${offset 25}${exec systemctl status tor.service | grep Bootstrap | cut -d" " -f7 | cut -d: -f1 | tail -1}

actually i want to replace ${color green} with:${color ${exec ~/.conky/ArchConky/service.sh}}
but no change!!!
any Idea?

Offline

#2 2016-03-02 17:49:34

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: problem:run bash script in conky

Does the script work on it's own - does it output what you'd expect (I gather the typo compounding the first two lines is just on the forums right)?

Also, FWIW, grep + cut + cut + tail + cut = awk.  Specifically, the following is equivalent to your first line:

LastStatus=$(systemctl status tor.service | awk '/Bootstrap/ { split($7,arr,"%"); print arr[1]; exit; }')

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#3 2016-03-02 18:35:49

stackoverflow
Member
Registered: 2015-09-23
Posts: 43

Re: problem:run bash script in conky

Trilby wrote:

Does the script work on it's own - does it output what you'd expect (I gather the typo compounding the first two lines is just on the forums right)?

Also, FWIW, grep + cut + cut + tail + cut = awk.  Specifically, the following is equivalent to your first line:

LastStatus=$(systemctl status tor.service | awk '/Bootstrap/ { split($7,arr,"%"); print arr[1]; exit; }')

yes it works properly..
i found the trouble.
conky does not show echo command !!!
try this:

${voffset 1}${font StyleBats:size'=10}${color exec echo green}j${voffset -1}${font DroidSans:size=8.65}${color3}${offset 5}java:$alignr ${exec systemctl status java | grep Active | cut -c 11-17}

and this line:

${color exec echo green}

seems dont be interepetd with conky sad

Offline

#4 2016-03-02 19:12:30

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: problem:run bash script in conky

I don't know conky very well, but I wouldn't expect ${color exec echo green} to work.  From looking at the documentation you probably want execp and have your script output the full ${color green} tag, eg:

${execp echo "${color green}"}

You should actually just have one script output the color and the content:

LastStatus=$(systemctl status tor.service | awk '/Bootstrap/ { split($7,arr,"%"); print arr[1]; exit; }')
if [[ $LastStatus -gt 99 ]]; then echo -n '${color green}'
elif [[ $LastStatus -gt 50 ]]; then echo -n '${color yellow}'
else echo -n '${color red}'
fi
echo "$LastStatus"'${color}'

Then call that script with execp in conky.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#5 2016-03-02 22:01:27

stackoverflow
Member
Registered: 2015-09-23
Posts: 43

Re: problem:run bash script in conky

no this is not work ..
i found the problem..
when we call this:

echo "$LastStatus"'${color}'

and other "echo" statements in privious post you send,the conky attempt to paint statments on Xorg exactly she see at that time smile
i want to "pass" some arguments from bash to conky.
is it possible?

Last edited by stackoverflow (2016-03-02 22:03:49)

Offline

#6 2016-03-02 23:10:52

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: problem:run bash script in conky

execp like I said.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

Board footer

Powered by FluxBB