Closed toorunaitou closed 1 year ago
That field should contain the Zabbix db version, something like 5000005
in Zabbix 5.0, or 6000000
in Zabbix 6.0... 0018
is a weird value.
With an empty $VERSION
I assume the query "select optional from dbversion;"
failed.
$DB_VER
has a value of 6000018
.
So in the code
re='(.*)([0-9]{2})([0-9]{4})'
if [[ $DB_VER =~ $re ]]; then
VERSION="_db-${DBTYPE}-${BASH_REMATCH[1]}.$(( ${BASH_REMATCH[2]} + 0 )).$(( ${BASH_REMATCH[3]} + 0 ))"
fi
${BASH_REMATCH[3]}
return the last 4 digits which is 0018
and bash doesn't like it.
And if I replace re='(.*)([0-9]{2})([0-9]{4})'
with re='(.*)([0-9]{2})([0-9]{2})'
bash doesn't complain and I get db-mysql-600.0.18.sql.gz
.
I'm not sure if there is any need for $VERSION
though.
The shell tries to interpret 0018 as an octal number, as it starts with a zero. It then proceeds to fail as 8 is not valid.
Looks like +0
was used to ensure the result was a number, even when the db version was shorter than expected, but with my current version of bash, there's no difference between $(( ))
and $(( +0 ))
.
I tested on 5.0.5, please change as following and check if it works for you too:
- VERSION="_db-${DBTYPE}-${BASH_REMATCH[1]}.$(( ${BASH_REMATCH[2]} + 0 )).$(( ${BASH_REMATCH[3]} + 0 ))"
+ VERSION="_db-${DBTYPE}-${BASH_REMATCH[1]}.$(( 10#0${BASH_REMATCH[2]} )).$(( 10#0${BASH_REMATCH[3]} ))"
It works, thank you!
..._db-mysql-6.0.18.sql.gz
Running script with mysql:
Trying to access $VERSION value has no output. Need to force base 10?