On Sun, 25 Feb 2024 10:50:05 +0000, 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... >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