The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
0

How can I check if either of 2 paths exist in VPN check?

asked 2015-03-06 22:22:27 +0000

robin108@gmail.com gravatar image

I use openvpn to connect to one provider and openconnect to another provider. In i3status I'd like to check if either path exists but I'm not sure how.

path_exists VPN { path = "/proc/sys/net/ipv4/conf/{vpn,tun}0" }

doesn't work and only one path statement will work. Seems I can only make the VPN check one path. Can I check if either path exists and give a YES/NO display in the status bar?

edit retag flag offensive close merge delete

Comments

This is a use case for condition/logical operators support in config files

biocyberman gravatar imagebiocyberman ( 2015-07-14 09:59:46 +0000 )edit

3 answers

Sort by » oldest newest most voted
0

answered 2015-03-08 00:00:04 +0000

joepd gravatar image

Openvpn has an option "writepid /path/to/file", traditionally that would be a file under /var/run. You can point i3status to examine the existence of that file.

edit flag offensive delete link more

Comments

both vpn clients have an option to write to a common pid file. Nice simple solution, thank you!

robin108@gmail.com gravatar imagerobin108@gmail.com ( 2015-03-14 19:02:23 +0000 )edit
0

answered 2015-07-14 10:38:26 +0000

biocyberman gravatar image

Below is my i3status config file, which has two unambiguous reports of VPN status (i.e. VPN for OpenVPN, Anyconnect for CISCO anyconnect). Pay attention to the consistency between 'order' lines and the run_watch definition below.

Bonus: I clean up other statuses that I do not use by commenting the corresponding 'order' lines.

# i3status configuration file.
# see "man i3status" for documentation.

# It is important that this file is edited as UTF-8.
# The following line should contain a sharp s:
# ß
# If the above line is not correctly displayed, fix your editor first!

general {
        colors = true
        interval = 5 
}

# order += "ipv6"
order += "disk /"
# order += "run_watch DHCP"
order += "run_watch VPN"
order += "run_watch Anyconnect"
order += "wireless wlan0"
# order += "ethernet eth0"
# order += "battery 0"
order += "load"
order += "tztime local"

wireless wlan0 {
        format_up = "W: (%quality at %essid) %ip"
        format_down = "W: down"
}

ethernet eth0 {
        # if you use %speed, i3status requires root privileges
        format_up = "E: %ip (%speed)"
        format_down = "E: down"
}

battery 0 { 
        format = "%status %percentage %remaining"
}

run_watch DHCP {
        pidfile = "/var/run/dhclient*.pid"
}

run_watch VPN {
        pidfile = "/sys/class/net/tun0/dev_id"
}

run_watch Anyconnect {
        pidfile = "/var/run/vpnagentd.pid"
        }   

tztime local {
        format = "%Y-%m-%d %H:%M:%S"
}

load {
        format = "%1min"
}

disk "/" {
        format = "%avail"
}
edit flag offensive delete link more
0

answered 2015-03-09 05:16:51 +0000

i3convert gravatar image

updated 2015-03-09 05:18:51 +0000

A somewhat ugly solution is to create a script that checks from time to time if either of the files exists and then creates some other file (say, /home/username/.i3/vpn). You then check if this other file exists. I'm attaching a Bash script that does this.

#!/bin/bash
MYFILE=/home/username/.i3/vpn
while true
do
    if [[ -e /proc/sys/net/ipv4/conf/vpn0 || -e /proc/sys/net/ipv4/conf/tun0 ]]
    then
        touch $MYFILE # this creates $MYFILE
    else
        rm -f $MYFILE # this deletes $MYFILE
    fi
    sleep 1 # check every second, modify to run the check at other intervals
done

Now you have to start the script automatically, which can be achieved by adding this line to the config exec --no-startup-id /home/username/.i3/checkVPN.sh, where /home/username/.i3/checkVPN.sh is the script.

edit flag offensive delete link more

Comments

Since i3status does the regular checking, you do not need to do the interval checking yourself. In a different approach, I prefer to have two unambiguous separate VPN status reports. I will post the solution in the answer because of limit for number of characters in comments.

biocyberman gravatar imagebiocyberman ( 2015-07-14 10:29:28 +0000 )edit

Question Tools

Stats

Asked: 2015-03-06 22:22:27 +0000

Seen: 677 times

Last updated: Jul 14