conky with conditionals

Forum Forums New users New Users and General Questions conky with conditionals

  • This topic has 3 replies, 2 voices, and was last updated Mar 31-12:33 pm by blur13.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #103745
    Member
    blur13

      Hi!

      So here is the problem. I use wttr.in to get weather data to output display in conky. For example:

      ${execi 1200 curl -sm 2 wttr.in/stockholm?format="%w"\&M}

      the -m 2 gives 2 seconds before the operation times out. Otherwise I’ve found that conky gets stuck when the curl command never finishes and nothing is displayed. I have to manually kill the curl processes in htop to get it to move on. And then the same thing repeats 20 min later. So -m 2 solves that problem. However, I have about five curl commands to wttr and some formatting and text that looks weird when nothing is returned from wttr. I’ve found wttr to be somewhat unreliable so this happens a lot. Enough times that I want to make a conditional along the lines of, “if curl times out, then…”. The exit code when curl times out is 28. So basically, when executing the above command, and the exit code is 28, then I dont want conky to use any of the code below. Any way to do this?

      #103747
      Member
      blur13
        Helpful
        Up
        0
        ::

        Maybe a smarter approach would be to use a shell script, run the above curl command and then, depending on the exit code, either run conky -c .conkyrc
        conky -c .conkyrc2

        where .conkyrc2 would be free from any curl wttr references. Anyone here good at scripting?

        #103748
        Member
        sybok
          Helpful
          Up
          1
          ::

          Hm, ‘conky -c’ is nice.
          How about the following usage of special variable ‘$?’ in BASH

          #!/bin/bash
          curl <whatever>
          exitcode="$?"
          if [ "${exitcode}" -eq 28 ]; then
            conky -c <config one>
          else
            conky -c <config two>
          fi

          See e.g. https://devhints.io/bash

          #103749
          Member
          blur13
            Helpful
            Up
            0
            ::

            Thank you! That is excellent. I simplified it to:

            #!/bin/bash
            
            curl <whatever>
            
            if [ $? -eq 28 ]; then
              conky -c <config one>
            else
              conky -c <config two>
            fi

            works great!

            • This reply was modified 1 month, 1 week ago by blur13.
          Viewing 4 posts - 1 through 4 (of 4 total)
          • You must be logged in to reply to this topic.