From ec28e63c30962818dab315d64ee4da10005e47fd Mon Sep 17 00:00:00 2001 From: Simon Nagl Date: Thu, 28 Apr 2016 22:41:15 +0200 Subject: [PATCH 1/1] Fix #282 use modern arithmetic expansion in shell Use $((.*)) instead of $[.*] The later one is old syntax --- charts.d/ap.chart.sh | 12 +++---- charts.d/apache.chart.sh | 66 +++++++++++++++++----------------- charts.d/cpufreq.chart.sh | 2 +- charts.d/example.chart.sh | 18 +++++----- charts.d/load_average.chart.sh | 2 +- charts.d/mysql.chart.sh | 42 +++++++++++----------- charts.d/nginx.chart.sh | 22 ++++++------ charts.d/nut.chart.sh | 16 ++++----- charts.d/opensips.chart.sh | 38 ++++++++++---------- charts.d/phpfpm.chart.sh | 18 +++++----- charts.d/postfix.chart.sh | 4 +-- charts.d/sensors.chart.sh | 14 ++++---- charts.d/squid.chart.sh | 8 ++--- charts.d/tomcat.chart.sh | 18 +++++----- tests/stress.sh | 28 +++++++-------- 15 files changed, 154 insertions(+), 154 deletions(-) diff --git a/charts.d/ap.chart.sh b/charts.d/ap.chart.sh index 10a65688..aed51c1b 100755 --- a/charts.d/ap.chart.sh +++ b/charts.d/ap.chart.sh @@ -54,25 +54,25 @@ ap_create() { # create the chart with 3 dimensions cat <$TMP_DIR/cpufreq.sh "cpufreq_update() {" - echo "CHART cpu.cpufreq '' 'CPU Clock' 'MHz' 'cpufreq' '' line $[cpufreq_priority + 1] $cpufreq_update_every" + echo "CHART cpu.cpufreq '' 'CPU Clock' 'MHz' 'cpufreq' '' line $((cpufreq_priority + 1)) $cpufreq_update_every" echo >>$TMP_DIR/cpufreq.sh "echo \"BEGIN cpu.cpufreq \$1\"" i=0 diff --git a/charts.d/example.chart.sh b/charts.d/example.chart.sh index 34a3bc1b..ad205046 100755 --- a/charts.d/example.chart.sh +++ b/charts.d/example.chart.sh @@ -22,11 +22,11 @@ example_check() { example_create() { # create the chart with 3 dimensions cat <>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.temp_$id \$1\"" divisor=1000 ;; @@ -138,7 +138,7 @@ sensors_create() { files="$( ls $path/in*_input 2>/dev/null )" files="$( sensors_check_files $files )" [ -z "$files" ] && continue - echo "CHART sensors.volt_$id '' '$name Voltage' 'Volts' 'voltage' 'sensors.volt' line $[sensors_priority + 2] $sensors_update_every" + echo "CHART sensors.volt_$id '' '$name Voltage' 'Volts' 'voltage' 'sensors.volt' line $((sensors_priority + 2)) $sensors_update_every" echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.volt_$id \$1\"" divisor=1000 ;; @@ -147,7 +147,7 @@ sensors_create() { files="$( ls $path/curr*_input 2>/dev/null )" files="$( sensors_check_files $files )" [ -z "$files" ] && continue - echo "CHART sensors.curr_$id '' '$name Current' 'Ampere' 'current' 'sensors.curr' line $[sensors_priority + 3] $sensors_update_every" + echo "CHART sensors.curr_$id '' '$name Current' 'Ampere' 'current' 'sensors.curr' line $((sensors_priority + 3)) $sensors_update_every" echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.curr_$id \$1\"" divisor=1000 ;; @@ -156,7 +156,7 @@ sensors_create() { files="$( ls $path/power*_input 2>/dev/null )" files="$( sensors_check_files $files )" [ -z "$files" ] && continue - echo "CHART sensors.power_$id '' '$name Power' 'Watt' 'power' 'sensors.power' line $[sensors_priority + 4] $sensors_update_every" + echo "CHART sensors.power_$id '' '$name Power' 'Watt' 'power' 'sensors.power' line $((sensors_priority + 4)) $sensors_update_every" echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.power_$id \$1\"" divisor=1000000 ;; @@ -165,7 +165,7 @@ sensors_create() { files="$( ls $path/fan*_input 2>/dev/null )" files="$( sensors_check_files $files )" [ -z "$files" ] && continue - echo "CHART sensors.fan_$id '' '$name Fans Speed' 'Rotations / Minute' 'fans' 'sensors.fans' line $[sensors_priority + 5] $sensors_update_every" + echo "CHART sensors.fan_$id '' '$name Fans Speed' 'Rotations / Minute' 'fans' 'sensors.fans' line $((sensors_priority + 5)) $sensors_update_every" echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.fan_$id \$1\"" ;; @@ -173,7 +173,7 @@ sensors_create() { files="$( ls $path/energy*_input 2>/dev/null )" files="$( sensors_check_files $files )" [ -z "$files" ] && continue - echo "CHART sensors.energy_$id '' '$name Energy' 'Joule' 'energy' 'sensors.energy' areastack $[sensors_priority + 6] $sensors_update_every" + echo "CHART sensors.energy_$id '' '$name Energy' 'Joule' 'energy' 'sensors.energy' areastack $((sensors_priority + 6)) $sensors_update_every" echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.energy_$id \$1\"" algorithm="incremental" divisor=1000000 @@ -183,7 +183,7 @@ sensors_create() { files="$( ls $path/humidity*_input 2>/dev/null )" files="$( sensors_check_files $files )" [ -z "$files" ] && continue - echo "CHART sensors.humidity_$id '' '$name Humidity' 'Percent' 'humidity' 'sensors.humidity' line $[sensors_priority + 7] $sensors_update_every" + echo "CHART sensors.humidity_$id '' '$name Humidity' 'Percent' 'humidity' 'sensors.humidity' line $((sensors_priority + 7)) $sensors_update_every" echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.humidity_$id \$1\"" divisor=1000 ;; diff --git a/charts.d/squid.chart.sh b/charts.d/squid.chart.sh index 5e1ebb06..f6154b25 100755 --- a/charts.d/squid.chart.sh +++ b/charts.d/squid.chart.sh @@ -63,21 +63,21 @@ squid_check() { squid_create() { # create the charts cat </dev/null | grep "update every = " | head -n 1 | cut -d '=' -f 2)" -[ $[ update_every + 1 - 1] -eq 0 ] && update_every=1 +[ $(( update_every + 1 - 1)) -eq 0 ] && update_every=1 entries="$(curl "$host/netdata.conf" 2>/dev/null | grep "history = " | head -n 1 | cut -d '=' -f 2)" -[ $[ entries + 1 - 1] -eq 0 ] && entries=3600 +[ $(( entries + 1 - 1)) -eq 0 ] && entries=3600 # to compare equal things, set the entries to 3600 max [ $entries -gt 3600 ] && entries=3600 @@ -35,8 +35,8 @@ formats=("jsonp" "json" "ssv" "csv" "datatable" "datasource" "tsv" "ssvcomma" "h options="flip|jsonwrap" now=$(date +%s) -first=$[now - (entries * update_every)] -duration=$[now - first] +first=$((now - (entries * update_every))) +duration=$((now - first)) file="$(mktemp /tmp/netdata-stress-XXXXXXXX)" cleanup() { @@ -50,22 +50,22 @@ do echo "curl --compressed --keepalive-time 120 --header \"Connection: keep-alive\" \\" >$file for x in {1..100} do - dt=$[RANDOM * duration / 32767] - st=$[RANDOM * duration / 32767] - et=$[ st + dt ] - [ $et -gt $now ] && st=$[ now - dt ] + dt=$((RANDOM * duration / 32767)) + st=$((RANDOM * duration / 32767)) + et=$(( st + dt )) + [ $et -gt $now ] && st=$(( now - dt )) - points=$[RANDOM * 2000 / 32767 + 2] - st=$[first + st] - et=$[first + et] + points=$((RANDOM * 2000 / 32767 + 2)) + st=$((first + st)) + et=$((first + et)) - mode=$[RANDOM * ${#modes[@]} / 32767] + mode=$((RANDOM * ${#modes[@]} / 32767)) mode="${modes[$mode]}" - chart=$[RANDOM * ${#charts[@]} / 32767] + chart=$((RANDOM * ${#charts[@]} / 32767)) chart="${charts[$chart]}" - format=$[RANDOM * ${#formats[@]} / 32767] + format=$((RANDOM * ${#formats[@]} / 32767)) format="${formats[$format]}" echo "--url \"$host/api/v1/data?chart=$chart&mode=$mode&format=$format&options=$options&after=$st&before=$et&points=$points\" \\" -- 2.39.2