! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Can't display a variable content with the <txt> tag
Status:
RESOLVED: FIXED
Product:
Xfce4-genmon-plugin
Component:
General

Comments

Description r.m.harris59 2018-05-30 11:23:22 CEST
I'm having an issue with the xfce4-genmon-plugin. I'm using it to monitor my vpn connection. Whenever I'm connected to my VPN (NordVPN using openpyn), it displays a symbol and the server I'm connected to with this command : $(ps ax | grep $(pidof openvpn) | perl -n -e '//(\w+) .nordvpn.com/ && print $1')

I recently decided I would also like it to display my current IP address (WAN)

I've written a short bash script that regularly checks the IP address with the command $(wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1) This is stored in an environment variable called IPPUBLIQUE and it works fine.

The next step was to write a script for the generic monitor plugin which is here :

    #!/bin/bash
    echo $IPPUBLIQUE
    ip=$IPPUBLIQUE
    echo $ip
    ip="IP:$ip"
    echo $ip
    checkvpn=$(nmcli con |grep tun0)

    if [ -n "$checkvpn" ]
    then
     echo "<img>/home/richard/Scripts/vpn.png</img>"
     echo "<txt>$ip; "$(ps ax | grep $(pidof openvpn) | perl -n -e '/\/(\w+)    \.nordvpn\.com/ && print $1')"</txt>"
     echo "<click>/home/richard/bin/./killvpngenmon.sh</click>"
     echo "<tool>Connected to VPN</tool>"
     echo "<img>/home/richard/Scripts/novpn.png</img>"

    else
     echo "<img>/home/richard/Scripts/novpn.png</img>"
     echo "<txt>$ip</txt>"
     echo "<click>gksudo /home/richard/bin/autovpn</click>"
     echo "<tool>Not connected to VPN</tool>"
     echo "<img>/home/richard/Scripts/vpn.png</img>"
    fi

When I test the script in a console, the values of each variable is correct and are printed out with the echo commands. They ll contain the correct IP addresses. However the monitor only displays the $ip as "IP: ". No matter what I do, it refuses to display my IP address, but if I set the variable manually (for example ip=192.168.0.1 instead of ip=$IPPUBLIQUE) then it works.

Can anyone help figure out what is going on and how I can correct it?

Thanks a lot
Comment 1 ToZ editbugs 2018-05-30 16:09:43 CEST
Version 3.3 of the plugin is quite old. Which distro are you using and is it possible to upgrade the genmon version?

On the 4.x series, your script seems to work fine (I can't test the vpn component).

I'll install the 3.3 version and see if there are any issues processing that string.
Comment 2 r.m.harris59 2018-05-30 17:57:43 CEST
Actually I'm running the 3.4 version of genmon-plugin on Debian Stretch but couldn't select it so put the most recent version (I should also point out that I'm not running xfce4 just the panel which is run in Cinnamon)
Comment 3 r.m.harris59 2018-05-30 18:05:42 CEST
I've been looking in to it today and found a work-around.

Basically everytime my vpn connects, it runs a script that stores the WAN ip address in a file. Here is the code : 

#!/bin/bash
ip=$(wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1)
ip="${ip:1}"
echo $ip > /tmp/.adresse


The genmon-plugin monitoring the VPN connection should then store the content of /tmp/.adresse into a variable with cat and display it with <txt> like this :

#!/bin/bash

ip= cat /tmp/.adresse
checkvpn=$(nmcli con |grep tun0)

if [ -n "$checkvpn" ]
 then

  echo "<img>/home/richard/Scripts/vpn.png</img>"
  echo "<txt>$ip; "$(ps ax | grep $(pidof openvpn) | perl -n -e '/\/(\w+)\.nordvpn\.com/ && print $1')"</txt>"
  echo "<click>/home/richard/bin/./killvpngenmon.sh</click>"
  echo "<tool>Connected to VPN</tool>"
  echo "<img>/home/richard/Scripts/novpn.png</img>"

 else

  echo "<img>/home/richard/Scripts/novpn.png</img>"
  echo "<txt>$ip</txt>"
  echo "<click>gksudo /home/richard/bin/autovpn</click>"
  echo "<tool>Not connected to VPN</tool>"
  echo "<img>/home/richard/Scripts/vpn.png</img>"

fi
'
However this still does not work (even though ip is set, I checked in the console and a well-placed 'echo $ip'), weirder still, this works : 

#!/bin/bash

checkvpn=$(nmcli con |grep tun0)
echo $checkvpn

if [ -n "$checkvpn" ]
 then

  echo "<img>/home/richard/Scripts/vpn.png</img>"
  echo "<txt>"$(cat /tmp/.adresse)"; "$(ps ax | grep $(pidof openvpn) | perl -n -e '/\/(\w+)\.nordvpn\.com/ && print $1')"</txt>"
  echo "<click>/home/richard/bin/./killvpngenmon.sh</click>"
  echo "<tool>Connected to VPN</tool>"
  echo "<img>/home/richard/Scripts/novpn.png</img>"

 else

  echo "<img>/home/richard/Scripts/novpn.png</img>"
  echo "<txt>"$(cat /tmp/.adresse)"</txt>"
  echo "<click>gksudo /home/richard/bin/autovpn</click>"
  echo "<tool>Not connected to VPN</tool>"
  echo "<img>/home/richard/Scripts/vpn.png</img>"

fi

I am now very happy as I can see my IP address, but I don't understand why the first solution doesn't work, could anyone help me figure this out? Am I coding wrong? Is there a specific syntax? (I know it sounds absurd since it works but not knowing why is driving me bananas)

Thanks for the help
Comment 4 ToZ editbugs 2018-10-27 14:47:03 CEST
Closing bug report.

Bug #14422

Reported by:
r.m.harris59
Reported on: 2018-05-30
Last modified on: 2018-10-27

People

CC List:
1 user

Version

Attachments

Additional information