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

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...

Similar Messages

  • [solved]Need help with a bash script for MOC conky artwork.

    I need some help with a bash script for displaying artwork from MOC.
    Music folders have a file called 'front.jpg' in them, so I need to pull the current directory from MOCP and then display the 'front.jpg' file in conky.
    mocp -Q %file
    gives me the current file playing, but I need the directory (perhaps some way to use only everything after the last  '/'?)
    A point in the right direction would be appreciated.
    thanks, d
    Last edited by dgz (2013-08-29 21:24:28)

    Xyne wrote:
    You should also quote the variables and output in double quotes to make the code robust, e.g.
    filename="$(mocp -Q %file)"
    dirname="${filename%/*}"
    cp "$dirname"/front.jpg ~/backup/art.jpg
    Without the quotes, whitespace will break the code. Even if you don't expect whitespace in any of the paths, it's still good coding practice to include the quotes imo.
    thanks for the tip.
    here it is, anyhow:
    #!/bin/bash
    filename=$(mocp -Q %file)
    dirname=${filename%/*}
    cp ${dirname}/front.jpg ~/backup/art.jpg
    then in conky:
    $alignr${execi 30 ~/bin/artc}${image ~/backup/art.jpg -s 100x100 -p -3,60}
    thanks for the help.
    Last edited by dgz (2013-08-29 21:26:32)

  • Can't get conky-cli and bash scripts to both display in dwm statusbar!

    I'm trying to configure my dwm status bar to display some simple information using conky-cli and bash scripts. At first I tried just letting conky run the bash scripts (for network and volume state), but this increased my cpu usage by about 5%, which is significant considering I normally have 1-3% usage when idle. Also, I wanted to keep conky because it makes the display of certain information easy, such as cpu & RAM usage.
    The problem is I'm having trouble getting both to display side by side. Here are the relevant parts of my .xinitrc:
    network(){
    iwconfig wlan0 2>&1 | grep -q no\ wireless\ extensions\. && {
    echo wired
    exit 0
    essid=`iwconfig wlan0 | awk -F '"' '/ESSID/ {print $2}'`
    stngth=`iwconfig wlan0 | awk -F '=' '/Quality/ {print $2}' | cut -d '/' -f 1`
    bars=`expr $stngth / 10`
    case $bars in
    0) bar='[-------]' ;;
    1) bar='[#------]' ;;
    2) bar='[##-----]' ;;
    3) bar='[###----]' ;;
    4) bar='[####---]' ;;
    5) bar='[#####--]' ;;
    6) bar='[######-]' ;;
    7) bar='[#######]' ;;
    *) bar='[--!!!--]' ;;
    esac
    echo $essid$bar
    exit 0
    volume(){
    vol=$(amixer get Master | awk -F'[]%[]' '/%/ {if ($7 == "off") { print "MM" } else { print $2 }}' | head -n 1)
    echo Vol: $vol%
    exit 0
    conky | while true; read line; do xsetroot -name "`$line` `volume` `network` `date '+%a %m-%d-%Y %I:%M%p'`"; done &
    exec dwm
    (let me know if it would help to post any other files)
    For some reason when I run this I only get the network/volume scripts and date running, updating every second (I think). The conky line just doesn't show up. I don't know what could be wrong, since I didn't see any error messages.
    An even better solution would be to just have shell scripts to display CPU and MEM usage. I have a dual-core cpu, cpu0 and cpu1. I'd like to see both percentages if possible, or at least a percentage that is an accurate average of the two or something. In conky-cli I have something that shows:
    cpu0/1: xx% xx%
    Also, seeing RAM usage would help a lot. In conky it shows:
    mem: xx% (xxxMB)
    These are the ways I would like to have bash scripts show them, if possible, but I have zero skill in bash programming. I made this an option in case it's easier/cleaner/less resource hungry than a conky solution. Personally, if they're about the same in these aspects, I would prefer something with conky and the shell scripts because conky is so extensible, yet it's only flaw is executing scripts with minimal resource usage.
    Help?

    Thanks. I was thinking of using load average to save a few characters, but I didn't quite understand the numbers. I'll try that once I get to my Linux box, but could you please explain or post a link to something that explains load average (what's low, high, normal, etc.)?
    EDIT: I found a website that explains loadavg. I now have my dwm status bar displaying it perfectly (yay!). Now I just need to add a few more things like battery status, etc. and I might be done. I'll probably post here if I have more questions, though.
    Thanks for your help!
    Last edited by Allamgir (2009-07-18 14:41:11)

  • [solved] Help with simple bash script

    #!/bin/bash
    current_state=cat /home/phil/.screen_state
    if ["$current_state" = "laptop"];
    then
    disper -S
    echo TV > .screen_state
    else
    disper -s
    echo laptop > .screen_state
    fi
    [phil@pwned ~]$ ./screenswitch.sh
    ./screenswitch.sh: line 3: /home/phil/.screen_state: Permission denied
    ./screenswitch.sh: line 5: [: missing `]'
    [phil@pwned ~]$ cat /home/phil/.screen_state
    laptop
    [phil@pwned ~]$
    I'm not sure why I'm getting the permission denied, and also I can't see whats wrong with line 5.
    Last edited by Dethredic (2011-08-21 19:46:57)

    IIRC you need spaces
    if [ "foo" = "foo" ]; then
    between '[' and another character.
    Edit: Got it.
    current_state=cat /home/phil/.screen_state
    This is plain wrong. I get 'Permission denied' too.
    Try
    current_state=$(cat /home/phil/.screen_state)
    Last edited by karol (2011-08-21 17:59:16)

  • Having problem with a bash script

    a few days ago this was working fine but now it will print the song name on the screen and doesn't go away like its supposed to(specified by the ``-d" option for osd_cat). anyone see something wrong? and wth did it work fine a few days ago? also, any general programming tips would be appreciated as this is really the most complicated script i've ever had to write.
    #!/usr/bin/env bash
    #Options:
    SCRIPT_DELAY=5
    COLOR=black
    POSITION=bottom
    OFFSET=-50
    MPD_HOST=127.0.0.1
    OSD_DURATION=5
    #extract just the artist/track name from mpc output
    function songname() { mpc | sed '2,3d' ; }
    #check if song has changed and break if no. if yes, update MPDSONG and print it on screen
    function printsong() {
    #if mpc's output is only 1 line, then mpc is stopped, so don't print anything
    if [ `mpc | wc -l` == 1 ]
    then return 1
    else
    while [ 1 ]
    do
    MPDSONG2=`songname`
    if [ "${MPDSONG}" == "${MPDSONG2}" ]
    then
    break
    else
    MPDSONG=`songname`
    echo $MPDSONG | osd_cat -d "${OSD_DURATION}" -p bottom -c black -u red -O 2 -i 6 --offset="${OFFSET}"
    --font=-adobe-helvetica-bold-*-*-*-34-*-*-*-*-*-*-*
    fi
    done
    fi
    while [ 1 ]
    do
    MPDSONG=`songname`
    sleep $SCRIPT_DELAY
    printsong
    done
    Last edited by _adam_ (2007-10-01 17:08:51)

    It is working or me. Though I removed to --font argument from the osd_cat command because I don't have the font installed.
    The second infinite loop in the function printsong seems a little useless to me.

  • Help with a bash script, please :)

    My bash is not good, not good at all, I can't work out why this will not work.  Any help is appreciated.
    [gary@Lister ~]$ cat .bin/kiss
    #!/bin/bash
    if [ -t /tmp/kiss ]
    killall mplayer
    else
    touch /tmp/kiss
    mplayer -playlist http://www.emapdigitalradio.com/emapdigitalradio/metafiles/kiss105.asx
    fi
    errors are
    [gary@Lister ~]$ kiss
    /home/gary/.bin/kiss: line 4: syntax error near unexpected token `else'
    /home/gary/.bin/kiss: line 4: `else'
    Thanks guys

    Arkane wrote:I didn't know about disown before, but if I understood things correctly it will make the program we just started independent of the shell running the script, so that it keeps running when the shell exits.
    Yeah, the shell keeps track of its jobs, and when the shell exits, it sends a SIGHUP signal to its jobs. The "disown" command tells the shell not to bother (and stop keeping track of this job), allowing you to close the shell without disturbing the running jobs.
    You can get this effect other ways also.
    Here is a better version of the script:
    #!/bin/bash
    CMD='mplayer -playlist http://www.emapdigitalradio.com/emapdigitalradio/metafiles/kiss105.asx'
    MPID=$(ps u -C mplayer | grep "$CMD" | awk '{print $2}')
    if [ -z "$MPID" ]; then
    #echo -n starting kiss...
    $CMD &>/dev/null &
    disown %1
    #echo done
    else
    #echo -n stopping kiss...
    kill $MPID
    #echo done
    fi
    This one is less ambitious in killing all instances of mplayer. Uncomment the "echo" lines if you want some feedback.

  • Conky doesn't display bash-script variables (array)

    I've been playing around with Conky and a bash script of mine. Unfortunately Conky displays only static text and not the array-variables in my script.
    In my script:
    ...some code here...
    echo "Static text: ${Variable[1]}"
    In my conkyrc:
    ...some code here...
    ${exec ~/Test/test.sh}
    The result is: "Static text: ". When running the script from the command line everything is fine. I've also tried with exec, execi, execp, texeci to no avail. Any ideas?
    Edit: I had to be more specific.
    Last edited by chilebiker (2009-10-06 03:30:20)

    Try echo -n "Static text: ${Variable[1]}"

  • [SOLVED] problem with spaces and ls command in bash script

    I am going mad with a bash script I am trying to finish. The ls command is driving me mad with spaces in path names. This is the portion of my script that is giving me trouble:
    HOMEDIR="/home/panos/Web Site"
    for file in $(find "$HOMEDIR" -type f)
    do
    if [ "$(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)")" -gt 30 ];
    then echo -e "File $file is $(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)") old\r" >> /home/panos/scripts/temp;
    fi
    done
    The dateDiff() function is defined earlier and the script works fine when I change the HOMEDIR variable to a path where there are no spaces in directory and file names. I have isolated the problem to the ls command, so a simpler code sample that also doesn't work correctly with path names with spaces is this:
    #!/bin/bash
    HOMEDIR="/home/panos/test dir"
    for file in $(find "$HOMEDIR" -type f)
    do
    ls -lh "$file"
    done
    TIA
    Last edited by panosk (2009-11-08 21:55:31)

    oops, brain fart. *flushes with embarrassment*
    -- Edit --
    BTW, for this kind of thing, I usually do something like:
    find "$HOMEDIR" -type f | while read file ; do something with "$file" ; done
    Or put those in an array:
    IFS=$'\n' ; files=($(find "$HOMEDIR" -type f)) ; unset IFS
    for file in "${files[@]}" ; do something with "$file" ; done
    The later method is useful when elements of "${files[@]}" will be used multiple times across the script.
    Last edited by lolilolicon (2009-11-09 08:13:07)

  • Writing to mplayer's stdin from bash script.

    I was just fulling with some bash script in order to automate the listening of my favorite radio stations via mplayer and a bash script. Going through the mplayers manual I saw the option -slave.
    -slave
    This option switches on slave mode. This is intended for use of MPlayer as a backend to other programs. Instead of intercepting keyboard events, MPlayer will read simplistic command lines from its stdin. The section SLAVE MODE PROTOCOL explains the syntax.
    At first I thought "ok, easy". I made some tries like "mplayer -slave -quiet .... < /tmp/stdin &" and then something like "echo -e 'mute' > /tmp/stdin" but it wouldn't work.
    Is it possible to send a process to the background inside a bash script and then write to it's stdin?
    SLAVE MODE PROTOCOL
    If the -slave option is given, playback is controlled by a line-based protocol. Each line must contain one command otherwise one of the following tokens:
    Commands
    seek <value> [type=<0/:1/:2>]
    Seek to some place in the movie. Type 0 is a relative seek of +/:- <value> seconds. Type 1 seek to <value> % in the movie. Type 2 is a seek to an absolute position of <value> seconds.
    audio_delay <value>
    Adjust the audio delay of value seconds
    quit
    Quit MPlayer
    pause
    Pause/:unpause the playback
    grap_frames
    Somebody know ?
    pt_step <value> [force=<value>]
    Go to next/:previous entry in the playtree.
    pt_up_step <value> [force=<value>]
    Like pt_step but it jumps to next/:previous in the parent list.
    alt_src_step <value>
    When more than one source is available it selects the next/:previous one (only supported by asx playlist).
    sub_delay <value> [abs=<value>]
    Adjust the subtitles delay of +/:- <value> seconds or set it to <value> seconds when abs is non zero.
    osd [level=<value>]
    Toggle osd mode or set it to level when level > 0.
    volume <dir>
    Increase/:decrease volume
    [contrast|brightness|hue|saturation] <-100-100> [abs=<value>]
    Set/:Adjust video parameters.
    frame_drop [type=<value>]
    Toggle/:Set frame dropping mode.
    sub_visibility
    Toggle subtitle visibility.
    sub_pos <value>
    Adjust subtitles position.
    vo_fullscreen
    Switch to fullscreen mode.
    tv_step_channel <dir>
    Select next/:previous tv channel.
    tv_step_norm
    Change TV norm.
    tv_step_chanlist
    Change channel list.
    gui_[loadsubtitle|about|play|stop]

    FIFO's are awesome and can be (ab)used for a lot of cool stuff.
    I've written some applications that do just what you are trying to do ( http://github.com/trapd00r/rmcd and http://github.com/trapd00r/RPD ), if you need inspiration.
    As for the backgrounding - you want to make a 'daemon', to detach from the running shell. See man fork, man 3 setsid and man 3 wait / man 3 waitpid (or my daemonize() function).

  • Double-clicking a Bash script and having it execute in it's directory

    Hi. I'm having some trouble with a Bash script I've been working on.
    The first command in the script is to copy all of the contents of the directory it's located in (including itself) to another folder.
    The Bash command I'm using is:
    cp -R . "/Some/Other/Folder/"
    This works fine when I run the program from the Terminal. E.g.: ./testscript
    But, I need this script to be double clickable in the Finder. I've associated it with Terminal, but when I double-click on it, instead of copying the files from the script's local folder, it starts recursively copying files from the home folder!
    I think this is because when I double-click on the script, it starts a new Terminal window at the home folder, and the dot portion of "cp ." now refers to the home folder, instead of the directory containing the script.
    Can anyone help me figure out how to be able to double click on the script to run it, yet have the script start in it's original folder?
    Thanks for any help.
    -Bassam
    Macbook Pro   Mac OS X (10.4.6)   Recently switched from Windows XP

    Thanks Steve, that worked perfectly.
    I did have to add a / to "$myFolder/" in the second line, so that the contents of the folder was copied, not the folder itself.
    Thanks!

  • Bash script won't run "sudo reboot" under cron, but perfect manually

    Hi Archers,
    I've got a weird problem with a bash script I use to run pacman and mythtv updates once a week via cron which also reboots itself so that new mythtv and kernels packages become active. This script works likes a charm when I run it manually as user from the command line. But when cron runs it (also as user) it executes everything EXCEPT the last "sudo reboot" command at the end. Sudoers seems to be setup right as it works fine from the command line. I could run this particular script with cron as root but I'd prefer not to update under root with the --asroot command.
    Any ideas? It seems like the permissions running manually and with cron are different somehow.
    Many thanks!
    Last edited by wdirksen (2012-10-09 13:07:28)

    OK, I'm going to reconsider this based on all your advices, but I'm still curious about why the command doesn't execute with cron. Related to this, I also find it strange that some root commands work fine with sudo, while others only work within a true root environment
    DSpider wrote:Post your /etc/sudoers file.
    So here's my sudoers file:
    ## User privilege specification
    root ALL=(ALL) NOPASSWD: ALL
    mythtv ALL=(ALL) NOPASSWD: ALL
    . . . and this is the script:
    #!/bin/bash
    sudo pacman -Syyu --noconfirm
    /usr/share/mythtv/optimize_mythdb.pl
    /usr/share/mythtv/mythconverg_backup.pl --rotate 20
    mythtvname="mythtv-git-$(date +%Y%m%d)-1-x86_64.pkg.tar.xz"
    cd /home/mythtv/AUR/mythtv-git
    makepkg
    sudo pacman -U $mythtvname --noconfirm
    sudo reboot
    Anything stick out here?
    Last edited by wdirksen (2012-10-09 19:32:52)

  • Bash Scripting with Conky -- How to implement?

    Hey Folks, my first post here and I'm looking for a bit of help. I've created a bash script to work with conky in which its purpose is to change the color of the battery bar depending on current voltage.
    Here's the bash script:
    #!/bin/bash
    # Change Conky battery color depending on charge
    chrg=`cat /proc/acpi/battery/BAT1/state | grep "remaining capacity" |
    awk '{print $3 }'`
    echo $chrg
    if [ $chrg -lt "3499" ]; then
    ${color red}${battery_percent BAT1}% ${battery_bar 4 BAT1}
    elif [ "$chrg" -lt "5100"]; then
    ${color orange}${battery_percent BAT1}% ${battery_bar 4 BAT1}
    else ${color green}${battery_percent BAT1}% ${battery_bar 4 BAT1}
    fi
    Essentially what it is supposed to do is grab and store the "remaining capacity" and if its lower than a certain point it changes color. What I'm having trouble with is actually implementing the colors into conky. Right now all it is doing is printing the charge as you can see. Any help would be appreciated. Thanks!

    I had this issue, took me three days to solve. Using if_match, put all your if_matches in a line, with each option having its color of choice, then put the bar, or % at the end.  You will need to make sure it is in sequential order so the color will not overlap the color you want for the state in the if_match. I know this is an old thread, I will edit my post when I get on my netbook with the code.
    I found this thread on a google search for bash and conky usages.
    [edit] here was my solution for the if_match using the battery.
    ${if_match ${battery_percent BAT1} <= 49}${color0}${endif}${if_match ${battery_percent BAT1} <= 20}${color9}${endif}${if_match ${battery_percent BAT1} >= 50}${color4}${endif}${battery BAT1} ${alignr}${battery_bar 6,160 BAT1}
    I have my colors set yellow for 49% and below, red 20% and lower, and last green for 50% and higher. Essentially this will pick yellow for under 49% and the if_match for red under 20%, the red will override the yellow, this is why order is important.
    Remember this is all in one line, now there are cleaner ways of setting this up using lua. That is something I am still working on.
    Last edited by mrknify (2014-03-05 17:09:59)

  • Bash script to trim all filenames with special characters recursively?

    Hi,
    I have a 30 GB directory full of data I recovered from a friend's laptop after her Windows XP crashed. I'd like to burn that data, but I can't, because many of the filenames contain weird characters (spaces, accents, things even worse that my XTerm displays as inverted question marks). So, mkisofs exits with an error.
    I'd like to clean that mess up, but it would take months to do that manually. Well, I only know a very little Bash, but I think this problem is already too heavy for my modest knowledge. Here's the problem:
    - check the contents of directory ~/backup recursively
    - find files whose filenames contain characters other than [A-Za-z0-9] and then maybe "-" and "_" and ".".
    - replace these characters either by an "_" or just erase them
    Now how would I translate that into a little Bash script?
    Cheers...

    Heyyyyy... nice idea

  • Bash script to dumpstream many files simultaneously with mplayer

    hi guys
    i have a problem which i´m sure can be solved with the power of bash scripting
    unfortunately i´m no bash scripting guru and all my experiments failed so far
    the problem:
    i have a file in which are links(streaminglinks)
    mplayer offers the funtion to dump such a stream with simply issuing
    mplayer -dumpstream mms://path/to/video -dumpfile video1
    for example.
    now i want mplayer to download this streams specified in the links-file automatically.
    basically all it required is a bash script which goes through the link file and generates a command like mplay -dumpstream <link> -dumpfile video<n>
    (where n is the nth link) and execute it.maybe there a even simpler solutions
    well since i´m not that experienced with bashscripting i can´t solve that problem at my self....
    i´m grateful for any help

    hey guys
    thx for the two scripts.
    my approach was nearly the same as your´s kraluz with the difference that it doesn´t work
    but they both have a little blemish
    they download the files sequentially not simultaneously
    how could that be realised
    thx in advance

  • Problem with "date -d" function in bash script. Leopard bug?

    I have this really nice rsync bash script that I use to make rotating snapshot backups of my different Ubuntu servers to a single backup server.
    I am now trying to use this same script on my Leopard machine, but it seems to have a serious problem with the following lines of code:
    lday=`date +'image-%Y-%m-%d-%H' -d '1 day ago'`
    lweek=`date +'image-%Y-%m-%d-%H' -d '1 week ago'`
    It generates the following error:
    date: illegal time format
    usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
    [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
    It's clear that it doesn't like the "-d '1 day ago'" part in my code.
    Is there a different way in Leopard to get yesterday's or last week's date in a bash script? Or is this a Leopard bug?
    Could someone please help me out? I've be trying to research this for the past 8 hours, but can't seem to find any solution to this problem.
    Thanks in advance.

    Is there a different way in Leopard to get yesterday's or last week's date in a bash script?
    date -v-1d
    date -v-7d

Maybe you are looking for