What's new

little help/suggestions needed

  • 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!

octopus

Part of the Furniture
I'm struggling with some programing issues and hope someone have done this already.

I wrote some scripts and get: cat: write error: Broken pipe and need som suggestion to solve it.

I'm reading from /tmp / vpnclient-1.log. When I resstart router "with / bin / cat vpnclient-1.log
https://pastebin.com/eXVxdJ4T

Is any other way to read from / tmp or other solution to solve this?

Thanks
Octopus
 
I'm struggling with some programing issues and hope someone have done this already.

I wrote some scripts and get: cat: write error: Broken pipe and need som suggestion to solve it.

I'm reading from /tmp / vpnclient-1.log. When I resstart router "with / bin / cat vpnclient-1.log
https://pastebin.com/eXVxdJ4T

Is any other way to read from / tmp or other solution to solve this?

Does the following extract the "CN=value" ?
Code:
awk '{FS="="} /VERIFY OK: depth=0/ {print $(NF);exit}' /tmp/vpnclient-1.log

EDIT: Updated to 'only match the first occurrence of the string'
 
Last edited:
Does the following extract the "CN=value" ?
Code:
awk '{FS="="} /VERIFY OK: depth=0/ {print $(NF)}' /tmp/vpnclient-1.log
Yes it does but multiple times. I need "grep -E -m 1" to.
Code:
octopus@RT-AC68U:/tmp/home/root# awk '{FS="="} /VERIFY OK: depth=0/ {print $(NF)}' /tmp/vpnclient-1.log
vpn61.prd.kista.ovpn.com
vpn61.prd.kista.ovpn.com
vpn61.prd.kista.ovpn.com
vpn61.prd.kista.ovpn.com
vpn61.prd.kista.ovpn.com
vpn61.prd.kista.ovpn.com
 
Try this instead:

Code:
CN3="$(grep -E -m 1 "VERIFY OK: depth=0" /tmp/vpnclient-1.log | cut -d ',' -f2 | cut -d "=" -f2)"; echo $CN3
 
Try this instead:

Code:
CN3="$(grep -E -m 1 "VERIFY OK: depth=0" /tmp/vpnclient-1.log | cut -d ',' -f2 | cut -d "=" -f2)"; echo $CN3
That working just fine.
Code:
octopus@RT-AC68U:/tmp/home/root# CN3="$(grep -E -m 1 "VERIFY OK: depth=0" /tmp/vpnclient-1.log | cut -d ',' -f2 | cut -d "=" -f2)"; echo $CN3
vpn61.prd.kista.ovpn.com

Thanks
I testing if it working with my other codes. :)
 
Yes it does but multiple times. I need "grep -E -m 1" to.
Code:
octopus@RT-AC68U:/tmp/home/root# awk '{FS="="} /VERIFY OK: depth=0/ {print $(NF)}' /tmp/vpnclient-1.log
vpn61.prd.kista.ovpn.com
vpn61.prd.kista.ovpn.com
vpn61.prd.kista.ovpn.com
vpn61.prd.kista.ovpn.com
vpn61.prd.kista.ovpn.com
vpn61.prd.kista.ovpn.com

Sorry :oops: … missed off the 'Only match first line'...see the updated code
 
Sorry :oops: … missed off the 'Only match first line'...see the updated code
When I put this together i dont resolv ip-number.
Code:
CN="$(grep -E -m 1 "VERIFY OK: depth=0" /tmp/vpnclient-1.log | cut -d ',' -f2 | cut -d "=" -f2)"
GROUP_IP="$(nslookup "$CN" | grep -woE '([0-9]{1,3}\.){3}[0-9]{1,3}' | awk 'NR>2');echo "$GROUP_IP"
:eek:
 
Last edited:
You're missing a closing double quote:
Code:
GROUP_IP="$(nslookup "$CN" | grep -woE '([0-9]{1,3}\.){3}[0-9]{1,3}' | awk 'NR>2')";echo "$GROUP_IP"
 
You're missing a closing double quote:
Code:
GROUP_IP="$(nslookup "$CN" | grep -woE '([0-9]{1,3}\.){3}[0-9]{1,3}' | awk 'NR>2')";echo "$GROUP_IP"
Hm I'm blind ...... too many characters and numbers. :rolleyes:
Thanks
 
It might be better not to rely on the IPv4 format for nslookup output (for example 'nslookup google.com ::' or 'nslookup microsoft.com ns1.msft.net'), likewise there might only be an IPv6 address listed.
Code:
GROUP_IP="$(nslookup "$CN" | awk 'NR>2&&$1=="Address:"{print $2;exit}')";echo "$GROUP_IP"
If you only want the IPv4 address that'd be better done on the nslookup side
Code:
GROUP_IP="$(nslookup -type=A "$CN" | awk 'NR>2&&$1=="Address:"{print $2;exit}')";echo "$GROUP_IP"
 
Last edited:
It might be better not to rely on the IPv4 format for nslookup output (for example 'nslookup google.com ::' or 'nslookup microsoft.com ns1.msft.net'), likewise there might only be an IPv6 address listed.
Code:
GROUP_IP="$(nslookup "$CN" | awk 'NR>2&&$1=="Address:"{print $2;exit}')";echo "$GROUP_IP"
If you only want the IPv4 address that'd be better done on the nslookup side
Code:
GROUP_IP="$(nslookup -type=A "$CN" | awk 'NR>2&&$1=="Address:"{print $2;exit}')";echo "$GROUP_IP"
Thanks but that not working:
Code:
GROUP_IP="$(nslookup -type=A "vpn61.prd.kista.ovpn.com" | awk 'NR>2&&$1=="Address:"{print $2;exit}')";echo "$GROUP_IP"
Code:
GROUP_IP="$(nslookup "vpn61.prd.kista.ovpn.com" | awk 'NR>2&&$1=="Address:"{print $2;exit}')";echo "$GROUP_IP"
 
Ah sorry, I didn't realise I was using entwares nslookup. Ignore the -type=A option.
Doesn't work
Code:
GROUP_IP="$(nslookup "vpn61.prd.kista.ovpn.com" | awk 'NR>2&&$1=="Address:"{print $2;exit}')";echo "$GROUP_IP"
 
Busybox's nslookup returns the info in a different format so you'd need something like:
Code:
GROUP_IP="$(nslookup "vpn61.prd.kista.ovpn.com" | awk 'NR>2&&$1=="Address"{print $3;exit}')";echo "$GROUP_IP"
 
Mmm, the format is completely different :confused:
This should work with either the builtin nslookup or the entware version.
Code:
GROUP_IP="$(nslookup "vpn61.prd.kista.ovpn.com" | awk 'NR>2&&/^Address/{if(NF==2){print $2}else{print $3};exit}')";echo "$GROUP_IP"

EDIT: Awk script could be written a little more concisely as
Code:
'NR>2&&/^Address/{print $(NF==2?2:3);exit}'
 
Last edited:
Busybox's nslookup returns the info in a different format so you'd need something like:
Code:
GROUP_IP="$(nslookup "vpn61.prd.kista.ovpn.com" | awk 'NR>2&&$1=="Address"{print $3;exit}')";echo "$GROUP_IP"
Mmm, the format is completely different :confused:
This should work with either the builtin nslookup or the entware version.
Code:
GROUP_IP="$(nslookup "vpn61.prd.kista.ovpn.com" | awk 'NR>2&&/^Address/{if(NF==2){print $2}else{print $3};exit}')";echo "$GROUP_IP"
Seems both working now. Thanks.
 

Similar threads

Sign Up For SNBForums Daily Digest

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