Results 1 to 4 of 4

Thread: Using Conky execpi variable with Bash conditional statement

  1. #1
    Join Date
    Nov 2016
    Beans
    3

    Question Using Conky execpi variable with Bash conditional statement

    I'm trying to write a simple "pinger" script which will periodically try to reach given IP address and output a colored message with information if it is available or not.

    I face the problem in which I can't set custom color inside Bash conditional statement. The Bash code has been inserted into execpi variable. Every time when I try to run Conky I get Bash error sh: 1: Bad substitution.

    Conky TEXT section:
    Code:
    ${color grey}Module_1: ${color}: ${execpi 10 if ping -c 1 -W 2 192.168.1.1 > /dev/null; then echo ${color green}"Success"${color}; else echo ${color red}"Failed"${color}; fi} | ${color grey}Module_2: ${color} ${execpi 10 if ping -c 1 -W 2 192.168.1.2 > /dev/null; then echo ${color green}"Success"${color}; else echo ${color red}"Failed"${color}; fi}
    Should the color variable be placed in some different way?

  2. #2
    Join Date
    Feb 2010
    Location
    Obscurial Springs
    Beans
    15,209
    Distro
    Ubuntu Budgie Development Release

    Re: Using Conky execpi variable with Bash conditional statement

    Have you tried an html color value rather than the word ? I have many different conky themes and multiple colors can be handled different ways.

    One way I've done it follows.

    Code:
    # Color scheme #
    
    default_color FF0033
    color1 6495ED
    color2 ffffff
    color3 ff0066
    In the cpu line further into the syntax with 2 colors.
    Code:
    ${color1}CPU1: ${cpu cpu1}% $alignr${color3}${cpubar cpu1 8,60}
    "Our intention creates our reality. "

    Ubuntu Documentation Search: Popular Pages
    Ubuntu: Security Basics
    Ubuntu: Flavors

  3. #3
    Join Date
    Mar 2017
    Beans
    1,018

    Re: Using Conky execpi variable with Bash conditional statement

    Put the conditonal statement in a bash script and escape the "$"s with "\".
    (make executable)

    Code:
    #!/bin/sh
    
    #Module1
    if ping -c 1 -W 2 192.168.1.1 > /dev/null; then 
        echo "\${color grey}Module_1: \${color green}Success\${color}"
    else 
        echo "\${color grey}Module_1: \${color red}Failed\${color}"
    fi
    
    #Module2
    if ping -c 1 -W 2 192.168.1.2 > /dev/null; then 
        echo "\${color grey}Module_2: \${color green}Success\${color}"
    else 
        echo "\${color grey}Module_2: \${color red}Failed\${color}"
    fi
    Then call the script in conky using your path to script.
    Code:
    ${execpi 10 /path/to/script}
    Last edited by again?; March 31st, 2017 at 10:47 PM.

  4. #4
    Join Date
    Nov 2016
    Beans
    3

    Re: Using Conky execpi variable with Bash conditional statement

    Thank you for proposed solution. The problem was with not escaped dollar signs. After I've added the backslashes everything works properly. Topic can be closed.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •