/bin/sh script error "arithmetic expression: expecting primary: " + " "
6,829
It seems the script expects several parameters which are set by OpenVPN in the environment variables like time_unix
and time_duration
, but they are missing.
You shouldn't directly run it. Have you set up the script correctly as explained in the document? See also OpenVPN manpage.
You might want to add printenv
to debug the script. All available variables are dumped to the log file by this.
log_file="/var/log/openvpn-disconnect.log"
printenv >> "$log_file"
Related videos on Youtube
Author by
bully
Updated on September 18, 2022Comments
-
bully almost 2 years
ERROR:
./client-disconnect.sh: 22: ./client-disconnect.sh: arithmetic expression: expecting primary: " + "
I just need to know how to fix it. It's for user accounting with OpenVPN.
Script
#!/bin/sh # Copyright Josh Cepek # This file is part of the openvpn-dynamic project, available from: # https://github.com/QueuingKoala/openvpn-dynamic # Dual-licensed under GPLv3 and BSD-3-clause # BEGIN User Disconnect Accounting log_file="/var/log/openvpn-disconnect.log" # Be platform friendly to both GNU and BSD-userland: if date --help >/dev/null 2>&1; then get_date() { date -d "@$1" +'%F-%H:%M'; } else get_date() { date -r "$1" +'%F-%H:%M'; } fi # Vars used in log line: #time: date_from="$(get_date $time_unix)" unix_to=$(($time_unix + $time_duration)) date_to="$(get_date $unix_to)" time_h=$(($time_duration / 3600)) time_m=$(( $time_duration % 3600 / 60 )) #bw: bw_up="$(( $bytes_received / 1000**2 ))\ .$(( $bytes_received % 1000**2 / 1000 ))" bw_down="$(( $bytes_sent / 1000**2 ))\ .$(( $bytes_sent % 1000**2 / 1000 ))" # Format the line for export: line="User '$common_name' \ using $ifconfig_pool_remote_ip \ from $trusted_ip:$trusted_port \ for $date_from to $date_to ($time_h:$time_m) \ BW(up/down) $bw_up/$bw_down" # Append it to the log echo "$line" >> "$log_file" # END User Disconnect Accounting exit 0
-
s3lph almost 9 yearsWhere do you set the variable
time_unix
initially? -
bully almost 9 yearsI tried changing time_unix to time_ascii as the env shows it as time_ascii. after doing this I got the error "date: invalid date '@'" Thanks to a post down below I am getting the ENV printed in the log file.
-
-
bully almost 9 yearsYes I did set the script up, but it failed. I was trying to figure out why. It runs the connect script fine, but when I d/c no log is generated.
-
yaegashi almost 9 yearsStrange. See variables actually set (the answer updated).
-
bully almost 9 yearsI tried changing time_unix to time_ascii as the env shows it as time_ascii. after doing this I got the error "date: invalid date '@'" Thanks to a post down below I am getting the ENV printed in the log fil
-
yaegashi almost 9 years
time_unix
is mandatory for that script to work. Maybe it's incompatible with OpenVPN you're running. You'd better edit your question and paste all theprintenv
output there.