/bin/sh 스크립트 오류 "산술 표현식: 예상 기본 값: " + ""

/bin/sh 스크립트 오류 "산술 표현식: 예상 기본 값: " + ""

실수: ./client-disconnect.sh: 22: ./client-disconnect.sh: arithmetic expression: expecting primary: " + "

나는 그것을 고치는 방법을 알아야합니다. OpenVPN 사용자 청구에 사용됩니다.

스크립트

#!/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

답변1

스크립트에는 OpenVPN이 time_unix및 등의 환경 변수에 설정하는 여러 매개변수가 필요한 것 같지만 time_duration누락되었습니다.

직접 실행하면 안 됩니다. 설명된 대로 스크립트를 올바르게 설정했습니까?문서? 당신은 또한 볼 수 있습니다OpenVPN 맨페이지.

printenv디버그 스크립트를 추가할 수도 있습니다 . 사용 가능한 모든 변수가 로그 파일에 덤프됩니다.

log_file="/var/log/openvpn-disconnect.log"
printenv >> "$log_file"

관련 정보