Announcement

Collapse
No announcement yet.

Conky pinger

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Conky pinger

    I currently live in a bit of an electromagnetic hole. I make do with an antenna on the roof, an amplifier, and a SIM router.
    Luckily, I get unlimited data and a double SIM for just over €20 a month, so it's OK... except the connection is... haphazard. Most of the time it's good, but not all.
    So, rather than wondering whether "it's me or them", I have a little "connection monitor" in a corner of the screen.
    It looks like this:

    Click image for larger version  Name:	conkping.png Views:	0 Size:	4.8 KB ID:	659542

    It consists of two parts: a little shell script that pings four hosts every ten seconds (each) and a conky that displays the results.
    They are both eminently editable to fit one's needs/preferences.
    The script:
    Code:
    #!/bin/bash
    while :
    do
    ping -c 1 -U 1.1.1.1 | awk '/64/ {print substr($7,6,3)}' > /home/not/.local/bin/pp1.txt
    sleep 10
    ping -c 1 -U 8.8.4.4 | awk '/64/ {print substr($7,6,3)}' > /home/not/.local/bin/pp2.txt
    sleep 10
    ping -c 1 -U 104.20.219.35 | awk '/64/ {print substr($7,6,3)}' > /home/not/.local/bin/pp3.txt
    sleep 10
    ping -c 1 -U 130.206.13.20 | awk '/64/ {print substr($7,6,3)}' > /home/not/.local/bin/pp4.txt
    sleep 10
    done
    The conky (relevant bit) :
    Code:
    ${color5}${execbar cat /home/not/.local/bin/pp1.txt | awk '// {print $1/6}'}
    ${voffset -13}${alignr}CFLR ${exec cat /home/not/.local/bin/pp1.txt}
    #
    ${execbar cat /home/not/.local/bin/pp2.txt | awk '// {print $1/6}'}
    ${voffset -13}${alignr}GOOG ${exec cat /home/not/.local/bin/pp2.txt}
    #
    ${color5}${execbar cat /home/not/.local/bin/pp3.txt | awk '// {print $1/6}'}
    ${voffset -13}${alignr}M247 ${exec cat /home/not/.local/bin/pp3.txt}
    #
    ${color5}${execbar cat /home/not/.local/bin/pp4.txt | awk '// {print $1/6}'}
    ${voffset -13}${alignr}IRIS ${exec cat /home/not/.local/bin/pp4.txt}
    /6 is an arbitrary divider I use to get a number between 1 and 100 most of the time (what conky requires) with the ping times I get here.
    Suggestions welcome :·)

    [EDIT I tried triple pinging and getting the average, but awk made a hash of it half the time :·/
    Last edited by Don B. Cilly; Jan 11, 2022, 09:26 AM.

    #2
    A regular ping can help keep a connection up, sometimes. My desktop's ethernet chip's tendency to disconnect (on a wired connection) is much reduced by running a ping to the router every few seconds.

    BTW,
    Code:
    p1=$(ping -c 1 -U 1.1.1.1 | awk '/64/ {print substr($7,6,3)}') ; echo $p1 > /home/not/.local/bin/pp1.txt
    would be simpler as
    Code:
    ping -c 1 -U 1.1.1.1 | awk '/64/ {print substr($7,6,3)}' > /home/not/.local/bin/pp1.txt
    ;
    Regards, John Little

    Comment


      #3
      Originally posted by jlittle View Post
      would be simpler as
      True :·) I defined a variable as I was playing with divisions and things, then I realised it was simpler to divide 'n conquer in conky ;·)

      Comment


        #4
        Actually, I found out that "$0" for a loop is a bad idea. It spawns infinite processes.
        I've updated the code with the "while/do/done" proper loop, and simplified according to jlittle's suggestion.

        Comment


          #5
          Originally posted by Don B. Cilly View Post

          $0 restarts it.
          That bit remains in your OP. As you changed your script to while/do/done, and you mentioned the $0 isn't desirable...
          Using Kubuntu Linux since March 23, 2007
          "It is a capital mistake to theorize before one has data." - Sherlock Holmes

          Comment


            #6
            Done. -

            Comment

            Working...
            X