What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Help my with an easy script to show vpn status! :)

  • Thread starter Thread starter Deleted member 27741
  • Start date Start date
D

Deleted member 27741

Guest
I have a super simple script that I want to modify and I know it will be child's play for you guys.

The below script outputs a 0 or a 2 depending on if the vpn is connected.

What I would like to do is make it a bit more sophisticated. So, if vpn_client1_state is 2 (connected) it would output something more informational like-

VPN client 1 connnected your ip address is <ip address>

Then if vpn_client1_state is 0 (disconnected), something like-

VPN client 2 disconnected your ip address is <ip address>

I think the reason I made it this simple in the first place is that I had trouble finding the WAN ip address when connected to the vpn client.


#!/bin/sh

logger -t $(basename $0) "STARTING SCRIPT, PARAMETER: $1"
echo "vpn_client1_state"
echo "CTRL+C to stop"
while true
do
nvram get "vpn_client1_state"
/bin/sleep 5s
done
 
This will give you your IP address for vpn_client1
Code:
ip route show table 111 | grep "via $(nvram get wan0_gateway)" | awk -F' ' '{ print $1 }'
 
@john9527 @000111

Just a question
I.m using:
Code:
ip route show table main| grep "via $(nvram get wan0_gateway)" | awk -F' ' '{ print $1 }'
and get output:
Code:
x6.227.xx.xxx
default
and need to cut away "default" . I.m not so good to use either cut or sed, how to implement?

Thank you
octopus
 
@john9527 @000111

Just a question
I.m using:
Code:
ip route show table main| grep "via $(nvram get wan0_gateway)" | awk -F' ' '{ print $1 }'
and get output:
Code:
x6.227.xx.xxx
default
and need to cut away "default" . I.m not so good to use either cut or sed, how to implement?

Thank you
octopus
For @000111 info, you would use table main instead of table 111 if you are not using policy based routing. Then, try this to strip out the 'default' answer

Code:
ip route show table main| grep "via $(nvram get wan0_gateway)" | grep -v "default" | awk -F' ' '{ print $1 }'
 
For @000111 info, you would use table main instead of table 111 if you are not using policy based routing. Then, try this to strip out the 'default' answer

Code:
ip route show table main| grep "via $(nvram get wan0_gateway)" | grep -v "default" | awk -F' ' '{ print $1 }'

@john9527 @000111
Thank you working.
I.m using main and policy routing.
 

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Staff online

Back
Top