Re: [Openvpn-users] Client history
> On Friday, February 23rd, 2024 at 4:39 PM, Bo Berglund > wrote: > On Fri, 23 Feb 2024 13:24:36 +0100, Gert Doering g...@greenie.muc.de wrote: > > > I think at this point you need to familiarize yourself with shell > > scripting to ensure that script is well-behaved. > > > And using shellcheck after editing/creating a script file also > > helps in getting rid of syntax errors etc... > > "sudo apt install shellcheck" if you do not already have it installed... > > > -- > Bo Berglund > Developer in Sweden > > > > ___ > Openvpn-users mailing list > Openvpn-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/openvpn-users Hello, I installed shellcheck and result is: # shellcheck script-events.sh In script-events.sh line 14: if [[ "$script_type" == "client-connect" ]]; then ^--^ SC2154 (warning): script_type is referenced but not assigned. In script-events.sh line 15: echo "$LOG_TIMESTAMP - $common_name connected with IP $trusted_ip" >> "$LOG_FILE" ^--^ SC2154 (warning): common_name is referenced but not assigned. ^-^ SC2154 (warning): trusted_ip is referenced but not assigned. For more information: https://www.shellcheck.net/wiki/SC2154 -- common_name is referenced but not... ___ Openvpn-users mailing list Openvpn-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-users
Re: [Openvpn-users] Client history
On Sun, 25 Feb 2024 10:50:05 +, Peter Davis via Openvpn-users wrote: >Hello, >I installed shellcheck and result is: > ># shellcheck script-events.sh > >In script-events.sh line 14: >if [[ "$script_type" == "client-connect" ]]; then > ^--^ SC2154 (warning): script_type is referenced but not > assigned. > > >In script-events.sh line 15: >echo "$LOG_TIMESTAMP - $common_name connected with IP $trusted_ip" >> > "$LOG_FILE" > ^--^ SC2154 (warning): common_name is > referenced but not assigned. > ^-^ SC2154 > (warning): trusted_ip is referenced but not assigned. > >For more information: > https://www.shellcheck.net/wiki/SC2154 -- common_name is referenced but > not... That is because shellcheck cammot find the assignments to these variables... And that is because they are actually put into the environment by openvpn prior to calling the script. So these warnings are OK, since you know that on execution they will exist. I use shellcheck to find other errors that are hard to find for example after editing scripts of hundreds of lines in size. Esay to introduce unpaired if-fi etc.. I find it very useful prior to doing a test run to weed out typos and missing stuff like broken if fi pairs and mismatches of ( ) and [ ] etc. The result above says that there is *no* problem with the script itself syntactically, just that shellcheck does not know of the environment varibles provided by the caller. -- Bo Berglund Developer in Sweden ___ Openvpn-users mailing list Openvpn-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-users
Re: [Openvpn-users] Client history
On Sun, 25 Feb 2024 15:31:20 +0100, Bo Berglund wrote: >On Sun, 25 Feb 2024 10:50:05 +, Peter Davis via Openvpn-users > wrote: > >>Hello, >>I installed shellcheck and result is: >> >># shellcheck script-events.sh >> >>In script-events.sh line 14: >>if [[ "$script_type" == "client-connect" ]]; then >> ^--^ SC2154 (warning): script_type is referenced but not >> assigned. >> >> >>In script-events.sh line 15: >>echo "$LOG_TIMESTAMP - $common_name connected with IP $trusted_ip" >> >> "$LOG_FILE" >> ^--^ SC2154 (warning): common_name is >> referenced but not assigned. >> ^-^ SC2154 >> (warning): trusted_ip is referenced but not assigned. >> >>For more information: >> https://www.shellcheck.net/wiki/SC2154 -- common_name is referenced but >> not... > >That is because shellcheck cammot find the assignments to these variables... > >And that is because they are actually put into the environment by openvpn prior >to calling the script. > >So these warnings are OK, since you know that on execution they will exist. > >I use shellcheck to find other errors that are hard to find for example after >editing scripts of hundreds of lines in size. Esay to introduce unpaired if-fi >etc.. > >I find it very useful prior to doing a test run to weed out typos and missing >stuff like broken if fi pairs and mismatches of ( ) and [ ] etc. > >The result above says that there is *no* problem with the script itself >syntactically, just that shellcheck does not know of the environment varibles >provided by the caller. HINT: - If you do not want this particular message to appear in a shellcheck output then you can add the following comment to the script on line #2: # shellcheck disable=SC2154 This will disable shellcheck from warning about these missing assignments. It makes sense to add into scripts that use variables supplied in the environment so this line could help in this case but not be used in other cases. -- Bo Berglund Developer in Sweden ___ Openvpn-users mailing list Openvpn-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-users
Re: [Openvpn-users] Client history
On Sun, 25 Feb 2024 10:50:05 +, Peter Davis via Openvpn-users wrote: >>Hello, >>I installed shellcheck and result is: >> >># shellcheck script-events.sh >> >>In script-events.sh line 14: >>if [[ "$script_type" == "client-connect" ]]; then >> ^--^ SC2154 (warning): script_type is referenced but not >> assigned. >> >> >>In script-events.sh line 15: >>echo "$LOG_TIMESTAMP - $common_name connected with IP $trusted_ip" >> >> "$LOG_FILE" >> ^--^ SC2154 (warning): common_name is >> referenced but not assigned. >> ^-^ SC2154 >> (warning): trusted_ip is referenced but not assigned. >> >>For more information: >> https://www.shellcheck.net/wiki/SC2154 -- common_name is referenced but >> not... >Hi, >Thanks again. >But my problem is that the script doesn't work at all. How do I find the cause? I cannot help more in debugging your environment, but I suggest that you test the script itself *without* involving openvpn in the testing. This can be done by creating a test script which will call the logging script like openvpn does and send the data as env vars like openvpn does in order to test the functions that way. I have done trhis test now with my script and it works just fine: Test script testlogging: --- #!/bin/bash export script_type="client-connect" export common_name="CommonName" export trusted_ip="192.168.129.253" ./server-events.sh exit 0 Script server-events.sh: #!/bin/bash # shellcheck disable=SC2154 # Log in local dir for testing LOG_FILE="server-events.log" # Log timestamp LOG_TIME=$(date "+%Y-%m-%d %H:%M:%S") # Log client connect or disconnect event with IP address if [ "$script_type" == "client-connect" ]; then echo "$LOG_TIME - $common_name connect IP $trusted_ip" >> "$LOG_FILE" elif [ "$script_type" == "client-disconnect" ]; then echo "$LOG_TIME - $common_name disconnect IP $trusted_ip" >> "$LOG_FILE" fi exit 0 - Place the scripts in the same test dir and execute ./testlogging Then there should be a logfile created in the same dir with the wanted data. If that is the case then the logging script works as it should and you have to look elsewhere for a reason for failure in your environment. -- Bo Berglund Developer in Sweden ___ Openvpn-users mailing list Openvpn-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-users
Re: [Openvpn-users] Client history
> On Sunday, February 25th, 2024 at 6:20 PM, Bo Berglund > wrote: > On Sun, 25 Feb 2024 15:31:20 +0100, Bo Berglund bo.bergl...@gmail.com wrote: > > > On Sun, 25 Feb 2024 10:50:05 +, Peter Davis via Openvpn-users > > openvpn-users@lists.sourceforge.net wrote: > > > > > Hello, > > > I installed shellcheck and result is: > > > > > > # shellcheck script-events.sh > > > > > > In script-events.sh line 14: > > > if [[ "$script_type" == "client-connect" ]]; then > > > ^--^ SC2154 (warning): script_type is referenced but not assigned. > > > > > > In script-events.sh line 15: > > > echo "$LOG_TIMESTAMP - $common_name connected with IP $trusted_ip" >> > > > "$LOG_FILE" > > > ^--^ SC2154 (warning): common_name is referenced but not assigned. > > > ^-^ SC2154 (warning): trusted_ip is referenced but not assigned. > > > > > > For more information: > > > https://www.shellcheck.net/wiki/SC2154 -- common_name is referenced but > > > not... > > > > That is because shellcheck cammot find the assignments to these variables... > > > > And that is because they are actually put into the environment by openvpn > > prior > > to calling the script. > > > > So these warnings are OK, since you know that on execution they will exist. > > > > I use shellcheck to find other errors that are hard to find for example > > after > > editing scripts of hundreds of lines in size. Esay to introduce unpaired > > if-fi > > etc.. > > > > I find it very useful prior to doing a test run to weed out typos and > > missing > > stuff like broken if fi pairs and mismatches of ( ) and [ ] etc. > > > > The result above says that there is no problem with the script itself > > syntactically, just that shellcheck does not know of the environment > > varibles > > provided by the caller. > > > HINT: > - > If you do not want this particular message to appear in a shellcheck output > then > you can add the following comment to the script on line #2: > > # shellcheck disable=SC2154 > > This will disable shellcheck from warning about these missing assignments. > It makes sense to add into scripts that use variables supplied in the > environment so this line could help in this case but not be used in other > cases. > > > -- > Bo Berglund > Developer in Sweden > > > > ___ > Openvpn-users mailing list > Openvpn-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/openvpn-users Hi, Thanks again. But my problem is that the script doesn't work at all. How do I find the cause? ___ Openvpn-users mailing list Openvpn-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-users
Re: [Openvpn-users] Client history
Hi, On Sun, Feb 25, 2024 at 06:50:39PM +, Peter Davis via Openvpn-users wrote: > But my problem is that the script doesn't work at all. How do I find the > cause? Last thing you said is it *does* work when logging to /tmp (though systemd hides it in the private /tmp directory). So if all you changed is the log path, and it stops working, this might be because systemd interferes again - or because directory permissions do not allow writing there. gert -- "If was one thing all people took for granted, was conviction that if you feed honest figures into a computer, honest figures come out. Never doubted it myself till I met a computer with a sense of humor." Robert A. Heinlein, The Moon is a Harsh Mistress Gert Doering - Munich, Germany g...@greenie.muc.de signature.asc Description: PGP signature ___ Openvpn-users mailing list Openvpn-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-users