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)

Similar Messages

  • How to make a systemd service for a bash script with pipes?

    I haven't been able to make a successful systemd service from this script.
    The script itself works (in terminal and xdg autostart), but systemd doesn't run anything after the first pipe (neither sed nor spd-say execute).
    Here's my service:
    [Unit]
    Description=Speak kernel and userspace messages
    [Service]
    Type=simple
    ExecStart=/usr/local/sbin/dmesg-speak
    [Install]
    WantedBy=multi-user.target
    Systemd says the script starts successfully, but only dmesg is started; it's output is not piped through sed or spd-say.
    I've also tried Type=forking without much success.
    Is there something I can do other than switching to sysv-init?
    Do I need IgnoreSIGPIPE=false?
    Last edited by quequotion (2015-02-12 17:07:21)

    fsckd wrote:The linked script appears to lack a hashbang. No hashbang = arbitrary interpretor.
    Yeah, that should probably be there. Since last post I've employed /usr/bin/bash in the service and added a hasbang, but sdp-say still does not run as a systemd service.
    I didn't test either option individually; the key seems to be finding an audio output accessible before user login. I am not certain:
    ccoffey wrote:If a pulseaudio session exists at all
    I am curious to try this:
    ccoffey wrote:run pulseaudio and dbus via XVFB.
    Setting DISPLAY as root would then allow you play audio.
    Still, it seems to me that ALSA would be available at some stage during boot, as is speech-dispatcher (for working with speakup!). If espeak were configured to play audio for root to ALSA, there would be a sound outlet for it (espeak can be used in pipeline mode without speech-dispatcher if need be), and pulseaudio would be probably be OK with that whenever it got around to starting (audio passed through alsa gets piped through, regardless of its source right?).
    I have tried the script with espeak instead of spd-say without success.
    Last edited by quequotion (2015-02-26 03:06:24)

  • Bash scripts with rox

    in rox-filer you can "send" files to bash scripts by right clicking on them and selecting the script.  for example:
    mogrify -format jpg $1
    i use these scripts all the time and they are really handy but they are limited.
    $1 uses the whole path and filename so it is almost impossible to do simple renaming or copy a file to a server without it being copied to /targetdir/fullpath/filename, for example.
    I am trying to work out how to get the filename into my scripts - with the full path - and then chop it up into path, filename, extention.  i read about word modifiers in bash e.g. !$:h - which works great on the command line but not in scripts - any ideas?

    You mean dirname, basename commands?
    This should be what you are looking for (I hope):
    http://www.splike.com/howtos/bash_faq.html

  • Bash script with sqlplus

    Hi, I hope I am in correct forum. I'm sorry, if not.
    I have following issue:
    #!/bin/bash
    ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
    ORACLE_SID=orcl
    PATH=$ORACLE_HOME/bin
    export ORACLE_HOME ORACLE_SID PATH
    sqlplus -s usera/oracle << EOF
    whenever sqlerror exit sql.sqlcode
    set serveroutput on feedback off
    -- some piece of code
    accept continue CHAR prompt 'To continue press ENTER'
    -- some piece of code
    exit;
    EOF
    I want to stop on line of accept command and wait for user input, but the code continues and doesn't wait for input.
    Is it possible to do this?

    It doesn't work because the sqlplus command is already taking its input from the "here" document (ending with EOF marker in your example). Once the "accept continue" line gets executed by sqlplus, the very next line of the "here" document satisfies the prompt.
    Try this instead:
    #!/bin/bash
    ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
    ORACLE_SID=orcl
    PATH=$ORACLE_HOME/bin
    export ORACLE_HOME ORACLE_SID PATH
    cat <<EOF > /tmp/sqlplus_script_text.$$.sql    ## the $$ is the current process ID, to prevent two running scripts from stepping on each other
    whenever sqlerror exit sql.sqlcode
    set serveroutput on feedback off
    -- some piece of code
    accept continue CHAR prompt 'To continue press ENTER'
    -- some piece of code
    exit;
    EOF
    sqlplus -s usera/oracle @/tmp/sqlplus_script_text.$$.sql
    rm -f /tmp/sqlplus_script_text.$$.sql

  • SorryServer with 443 - How to implement ?

    Please clarify and correct my SorryServer with 443 scenario. normally, clients will be connected to S1 or S2 with the server's certification.
    1. If S1 and S2 both down, clients will be redirecting to SorryServer and SorryServer will be issued the certification.
    2. Client have a certification from server. S1 and S2 down in the middle of communication, what happen the client ? Is the client will get a certification request from SorryServer ? I'm not clear for the certification which already got from the server.
    3. Last question. Is this right way to implement SorryServer with 443 ?
    service S1
    ip address 1.1.1.1
    port 443
    service S2
    ip address 1.1.1.2
    port 443
    service SorryServer
    ip address 1.1.2.1
    port 443
    content SecureServer
    vip address 2.2.2.2
    add service S1
    add service S2
    advanced-balance sticky-srcip
    primarySorry SorryServer
    port 443
    Thanks in advance.

    Well,
    Assuming you activate the services with the "active" command.. :)
    If something goes wrong in the middle of a flow (or conneciton) then there is not much we will do. The sorry server does not have a socket for that specific connection. If we did send it there, we would only get a TCP RST response. The sorry service will get all NEW connections if all the other services go down.
    Other than not having "active" services, and I am not sure on the content rule (It needs to be active also!) the way you have configured it is fine.
    -Steve

  • Bash script with Cron job

    Hello,
    This is my first post:-)
    we have developed one script to do basic LDAP healthcheck and tested. It's working fine. But have to run manually daily. I want to put that script in cron job.
    So that it generates reports automatically. Can some one please give me the hit on it or any links which i could understand more easily.
    Thanks.

    Hi,
    this doesn't look exactly like a DS-related question, however the best option would be 'man crontab' / 'man cron' and read the man pages ;-)
    But, assuming you're running Solaris 10... and you would like to run your script every day of every month of every week at 1:30 AM... you should add the following line to your crontab:
    1 30 * * * /full/path/to/your/script.sh
    HTH,
    Marco

  • [SOLVED] Bash scripting - figure out how much you've downloaded

    Hi
    How would I aproach displaying how much (in mb/kb/gb whatever) I've downloaded?
    Thanks
    Last edited by valvet (2010-11-04 13:10:13)

    There's also http://www.archlinux.org/packages/?sort … =&limit=50
    [karol@black ~]$ vnstat -d
    eth0 / daily
    day rx | tx | total | avg. rate
    ------------------------+-------------+-------------+---------------
    10/02/10 525.89 MiB | 28.77 MiB | 554.66 MiB | 52.59 kbit/s
    10/03/10 850.30 MiB | 20.01 GiB | 20.84 GiB | 2.02 Mbit/s
    10/04/10 353.02 MiB | 20.26 MiB | 373.28 MiB | 35.39 kbit/s
    10/05/10 601.78 MiB | 42.41 MiB | 644.19 MiB | 61.08 kbit/s
    10/06/10 471.46 MiB | 26.29 MiB | 497.75 MiB | 47.19 kbit/s
    10/07/10 312.86 MiB | 15.24 MiB | 328.10 MiB | 31.11 kbit/s
    10/08/10 250.51 MiB | 13.85 MiB | 264.36 MiB | 25.07 kbit/s
    10/09/10 456.25 MiB | 22.86 MiB | 479.11 MiB | 45.43 kbit/s
    10/10/10 1.21 GiB | 43.15 MiB | 1.25 GiB | 121.82 kbit/s
    10/11/10 442.58 MiB | 21.45 MiB | 464.02 MiB | 44.00 kbit/s
    10/12/10 757.99 MiB | 33.45 MiB | 791.44 MiB | 75.04 kbit/s
    10/13/10 274.19 MiB | 18.22 MiB | 292.41 MiB | 27.72 kbit/s
    10/14/10 1.11 GiB | 48.94 MiB | 1.16 GiB | 112.59 kbit/s
    10/15/10 1.08 GiB | 42.71 MiB | 1.12 GiB | 108.95 kbit/s
    10/16/10 921.70 MiB | 32.01 MiB | 953.71 MiB | 90.43 kbit/s
    10/17/10 929.25 MiB | 37.68 MiB | 966.94 MiB | 91.68 kbit/s
    10/18/10 1.78 GiB | 73.96 MiB | 1.85 GiB | 179.53 kbit/s
    10/19/10 391.16 MiB | 19.23 MiB | 410.39 MiB | 38.91 kbit/s
    10/20/10 1.30 GiB | 42.81 MiB | 1.34 GiB | 130.33 kbit/s
    10/21/10 2.67 GiB | 77.57 MiB | 2.75 GiB | 267.06 kbit/s
    10/22/10 1.17 GiB | 36.96 MiB | 1.21 GiB | 117.29 kbit/s
    10/23/10 3.91 GiB | 104.04 MiB | 4.01 GiB | 389.56 kbit/s
    10/24/10 4.43 GiB | 124.12 MiB | 4.55 GiB | 441.50 kbit/s
    10/25/10 2.48 GiB | 71.18 MiB | 2.55 GiB | 247.22 kbit/s
    10/26/10 7.25 GiB | 146.55 MiB | 7.39 GiB | 717.75 kbit/s
    10/27/10 0.98 GiB | 35.87 MiB | 1.02 GiB | 98.78 kbit/s
    10/28/10 1.22 MiB | 599 KiB | 1.81 MiB | 0.17 kbit/s
    11/02/10 1.77 GiB | 30.93 MiB | 1.80 GiB | 174.33 kbit/s
    11/03/10 961.69 MiB | 44.55 MiB | 0.98 GiB | 95.41 kbit/s
    11/04/10 1.09 GiB | 44.35 MiB | 1.13 GiB | 170.49 kbit/s
    ------------------------+-------------+-------------+---------------
    estimated 1.69 GiB | 68 MiB | 1.76 GiB |
    [karol@black ~]$ vnstat -m
    eth0 / monthly
    month rx | tx | total | avg. rate
    ------------------------+-------------+-------------+---------------
    Feb '10 66.99 GiB | 4.72 GiB | 71.71 GiB | 248.65 kbit/s
    Mar '10 31.77 GiB | 2.68 GiB | 34.45 GiB | 107.89 kbit/s
    Apr '10 28.77 GiB | 2.50 GiB | 31.26 GiB | 101.18 kbit/s
    May '10 6.38 GiB | 682.79 MiB | 7.05 GiB | 22.08 kbit/s
    Jun '10 6.10 GiB | 347.45 MiB | 6.44 GiB | 20.83 kbit/s
    Jul '10 41.02 GiB | 1.73 GiB | 42.75 GiB | 133.89 kbit/s
    Aug '10 49.31 GiB | 2.91 GiB | 52.21 GiB | 163.52 kbit/s
    Sep '10 14.49 GiB | 939.38 MiB | 15.40 GiB | 49.85 kbit/s
    Oct '10 41.93 GiB | 21.36 GiB | 63.29 GiB | 198.21 kbit/s
    Nov '10 3.79 GiB | 119.83 MiB | 3.91 GiB | 104.14 kbit/s
    ------------------------+-------------+-------------+---------------
    estimated 31.21 GiB | 979 MiB | 32.17 GiB |

  • BASH Script - Launch App with

    I'm trying to write a simple BASH script that will laungh an program, but that program needs command line arguments.
    When I put it in quotes it says it can't find the file, if I don't use quotes then it won't run the program with the command line arguments. How can I launch a program using a BASH script with command line arguments?
    Thanks in advance

    #!/bin/bash
    /Users/name/Desktop/Directory/app -f configfile

  • Using admin_client.jar from bash script

    Hello,
    When I make a call "java -jar admin_client.jar" from a bash script I always get 0 for $? even when there are errors reported in the console. How can I check the status correctly?
    S

    Greetings,
    Can you see the console when running the script? I would try to test something simple like -testDatabaseConnection and you should see a result. If you cannot login the the server directly, pipe the output to a file. Next, build up your bash script with additional complexity as you go. Post the results here for the group to analyze.
    THX
    -Michael
    Edited by: Michael F. Hardy on Dec 2, 2008 2:02 PM

  • [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)

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

  • 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)

  • How do I save a "bash" script? (in attempt to fix one of my other problems)

    Here is my original problem:
    http://discussions.apple.com/thread.jspa?threadID=2195627&tstart=0
    I came across this that sounds like it will help my issue:
    http://www.macosxhints.com/article.php?story=20090316190817357
    However, what am I supposed to do with that code? Put it in the Terminal? Save it as an Apple Script? I also got the "lingon" program set up, all I need to do is figure how how to save this "bash" script and all set!
    Any ideas?
    -Scott

    This link might help as it shows how to create the plist using lingon:
    http://mymacfixes.blogspot.com/2009/06/how-do-i-stop-clicking-noise-from-hard.ht ml

  • 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]}"

  • 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

Maybe you are looking for