Simulate SQL inner join in bash?
by taylorkh from LinuxQuestions.org on (#4Y94K)
I am using a Raspberry Pi as a gateway, router, DHCP and VPN connection sharing box for my home LAN. I have a systemd job which connects the VPN, monitors it and reconnects if it drops. Recently I upgraded my script so that I could control the operation of the VPN by posting flag files to a directory on the Pi. I then wrote a script which I run on my workstation which will post the appropriate flag files to the Pi using ssh. Works great. For my next trick I want my workstation script to interrogate the Pi to see which flag file is present and report what more the VPN is in before I make a change.
The flag files are:
(none) - default, connect to "fastest" VPN server using ProtonVPN tool
vpnoff - disconnect the VPN and leave it off
manual - allow me to specify the VPN server to connect to
good - connect to a random server from a list of "good" servers (which do not offend ebay, amazon etc.)
I can determine the flag file present, if any, byCode:=( $(ssh magic ls /etc/protonvpn/) ) If the return code is 1 I can assume that no file is present and I am in default mode. If not I need to compare the name of the file present against my list of vpnoff, manual, good.
Granted I only need to compare name of the file which I have found against three possible values. I can do this with an if elif fi structure with some greps but I am wondering if there is a cooler way :scratch: Sort of like an inner join in SQL. Just a learning experience now but it might come in handy if I have to look against a larger list some day.
Any suggestions?
TIA.
Ken


The flag files are:
(none) - default, connect to "fastest" VPN server using ProtonVPN tool
vpnoff - disconnect the VPN and leave it off
manual - allow me to specify the VPN server to connect to
good - connect to a random server from a list of "good" servers (which do not offend ebay, amazon etc.)
I can determine the flag file present, if any, byCode:=( $(ssh magic ls /etc/protonvpn/) ) If the return code is 1 I can assume that no file is present and I am in default mode. If not I need to compare the name of the file present against my list of vpnoff, manual, good.
Granted I only need to compare name of the file which I have found against three possible values. I can do this with an if elif fi structure with some greps but I am wondering if there is a cooler way :scratch: Sort of like an inner join in SQL. Just a learning experience now but it might come in handy if I have to look against a larger list some day.
Any suggestions?
TIA.
Ken