You are not logged in.

#1 2012-08-26 03:08:21

flagators
Member
Registered: 2012-02-09
Posts: 4

Conky with a bash script

I am trying to change the color of my CPU temp text in conky to green, yellow or red based on the CPU temp.  I am getting this in my conky:
Temperature:  color green33

Here is my conky line:

${voffset 1}${goto 40}Temperature: ${font Droid Sans:style=Bold:size=8}${execpi 120 sensors | grep Core0 | paste -s | cut -c15-18 | xargs ~/.conky/colorize.sh}${hwmon 0 temp 1}°C${color}${font}${alignr}

Here is my bash script:

#!/bin/bash
# colorize.sh

COOL=65
WARM=80

if [[ $1 < $COOL ]];
then
  echo "color green"
elif [[ $1 > $WARM ]];
then
  echo "color red"
else
  echo "color yellow"
fi
exit 0

Any help would be greatly appreciated.

Thanks

Offline

#2 2012-08-26 05:44:32

debdj
Member
Registered: 2012-01-19
Posts: 163

Re: Conky with a bash script

It doesn't work like that.
Either you have to echo rgb color codes or echo something like color1 .. color5 and in the conky script assign the variables their color codes.

For e.g. in .conkyrc --

color1 8AD749 # Green
color2 EECE01 # Yellow
color3 F80E27 # Red

and in the script:

if [[ $1 < $COOL ]];
then
  echo -n '${color1}'
elif [[ $1 > $WARM ]];
then
  echo -n '${color3}'
else
  echo -n '${color2}"
f

Last edited by debdj (2012-08-26 05:46:54)

Offline

#3 2012-08-26 08:16:37

Roken
Member
From: UK
Registered: 2012-01-16
Posts: 731

Re: Conky with a bash script

why not include the whole sensors line in bash, rather than messing up conky that way:

temp=`sensors | grep core0 | cut -c15-18`
if [[ $temp < $COOL ]];
then
  echo -n '${color1}$temp'
elif [[ $temp > $WARM ]];
then
  echo -n '${color3}$temp'
else
  echo -n '${color2}$temp"
fi

and then in conky:

${voffset 1}${goto 40}Temperature: ${font Droid Sans:style=Bold:size=8}${execpi 120 sh ~/.conky/colorize.sh}°C${color}${font}${alignr}

[img=Speedtest]http://www.speedtest.net/my-result/5145583518[/img]

Nvidia GTX 670 2Gb, AMD Phenom II X4 (965BE) @ 3.6 Ghz (Overclocked) 8GB RAM
Linux user #545703

Offline

#4 2012-08-26 08:27:24

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 20,068
Website

Re: Conky with a bash script

Roken wrote:
temp=`sensors | grep core0 | cut -c15-18`

I'm a little OCD about these pipes... Awk seems so much tidier.

awk '/Core 0/ {print +$3}' <(sensors)

Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Online

#5 2012-08-26 08:56:15

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: Conky with a bash script

jasonwryan wrote:

I'm a little OCD about these pipes...

That's what Mario said!


ᶘ ᵒᴥᵒᶅ

Offline

#6 2012-08-26 11:53:13

El_Belgicano
Member
Registered: 2011-09-15
Posts: 4

Re: Conky with a bash script

Using exec(p)(i) makes your conky run heavier, so, why wouldn't you use the built-in conky variables to achieve the same...

I'm using: (before "TEXT")

template2 ${color2}${if_match ${hwmon \1 temp \2}>75}${color orange}${if_match ${hwmon \1 temp \2}>90}${color red}${endif}${endif}${hwmon \1 temp \2}${color1}

and i call them like: (after "TEXT")

Temp ${template2 0 1}/${template2 1 1}/${template2 2 2}/${template2 2 4}

Of course you need to find out what numbers you need to pass to hwmon...

Offline

#7 2012-08-26 21:39:19

flagators
Member
Registered: 2012-02-09
Posts: 4

Re: Conky with a bash script

Thanks everyone.  This is my first attemp at bash.

Offline

#8 2012-08-27 13:09:37

debdj
Member
Registered: 2012-01-19
Posts: 163

Re: Conky with a bash script

@flagators just for reference this is a great book for starters:: http://linuxcommand.org/tlcl.php
and this place got me started in shell scripting:: http://www.ibm.com/developerworks/views … +UNIX+Part

Offline

#9 2012-08-28 03:22:29

flagators
Member
Registered: 2012-02-09
Posts: 4

Re: Conky with a bash script

@debdj Thanks!

Offline

Board footer

Powered by FluxBB