diff options
author | Paweł Krupa <pawel@krupa.net.pl> | 2018-09-13 10:24:05 +0200 |
---|---|---|
committer | Costa Tsaousis <costa@tsaousis.gr> | 2018-09-13 11:24:05 +0300 |
commit | fef1d0c06ed0ecc9da2f27655f885027315fc91e (patch) | |
tree | 83efe3d412c5ac76901a5879f6b8cd735924ca17 /charts.d | |
parent | 16b2a57ad0ab7ac40a7e1ecdebcc02c881086366 (diff) |
more linting of bash modules (#4183)
Diffstat (limited to 'charts.d')
-rw-r--r-- | charts.d/cpufreq.chart.sh | 29 | ||||
-rw-r--r-- | charts.d/example.chart.sh | 12 | ||||
-rw-r--r-- | charts.d/exim.chart.sh | 4 | ||||
-rw-r--r-- | charts.d/hddtemp.chart.sh | 10 |
4 files changed, 32 insertions, 23 deletions
diff --git a/charts.d/cpufreq.chart.sh b/charts.d/cpufreq.chart.sh index 8613a000ea..bad06d1c79 100644 --- a/charts.d/cpufreq.chart.sh +++ b/charts.d/cpufreq.chart.sh @@ -20,7 +20,7 @@ cpufreq_update_every= cpufreq_priority=10000 cpufreq_find_all_files() { - find $1 -maxdepth $cpufreq_sys_depth -name scaling_cur_freq 2>/dev/null + find "$1" -maxdepth $cpufreq_sys_depth -name scaling_cur_freq 2>/dev/null } # _check is called once, to find out if this chart should be enabled or not @@ -30,30 +30,30 @@ cpufreq_check() { # - 0 to enable the chart # - 1 to disable the chart - [ -z "$( cpufreq_find_all_files $cpufreq_sys_dir )" ] && return 1 + [ -z "$( cpufreq_find_all_files "$cpufreq_sys_dir" )" ] && return 1 return 0 } # _create is called once, to create the charts cpufreq_create() { - local dir= file= id= i= + local dir file id i # we create a script with the source of the # cpufreq_update() function # - the highest speed we can achieve - - [ $cpufreq_source_update -eq 1 ] && echo >$TMP_DIR/cpufreq.sh "cpufreq_update() {" + [ $cpufreq_source_update -eq 1 ] && echo >"$TMP_DIR/cpufreq.sh" "cpufreq_update() {" 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\"" + echo >>"$TMP_DIR/cpufreq.sh" "echo \"BEGIN cpu.cpufreq \$1\"" i=0 - for file in $( cpufreq_find_all_files $cpufreq_sys_dir | sort -u ) + for file in $( cpufreq_find_all_files "$cpufreq_sys_dir" | sort -u ) do i=$(( i + 1 )) - dir=$( dirname $file ) + dir=$( dirname "$file" ) cpu= - [ -f $dir/affected_cpus ] && cpu=$( cat $dir/affected_cpus ) + [ -f "$dir/affected_cpus" ] && cpu=$( cat "$dir/affected_cpus" ) [ -z "$cpu" ] && cpu="$i.a" id="$( fixid "cpu$cpu" )" @@ -61,14 +61,15 @@ cpufreq_create() { debug "file='$file', dir='$dir', cpu='$cpu', id='$id'" echo "DIMENSION $id '$id' absolute 1 1000" - echo >>$TMP_DIR/cpufreq.sh "echo \"SET $id = \"\$(< $file )" + echo >>"$TMP_DIR/cpufreq.sh" "echo \"SET $id = \"\$(< $file )" done - echo >>$TMP_DIR/cpufreq.sh "echo END" + echo >>"$TMP_DIR/cpufreq.sh" "echo END" - [ $cpufreq_source_update -eq 1 ] && echo >>$TMP_DIR/cpufreq.sh "}" + [ $cpufreq_source_update -eq 1 ] && echo >>"$TMP_DIR/cpufreq.sh" "}" # ok, load the function cpufreq_update() we created - [ $cpufreq_source_update -eq 1 ] && . $TMP_DIR/cpufreq.sh + # shellcheck disable=SC1090 + [ $cpufreq_source_update -eq 1 ] && . "$TMP_DIR/cpufreq.sh" return 0 } @@ -81,8 +82,8 @@ cpufreq_update() { # do all the work to collect / calculate the values # for each dimension # remember: KEEP IT SIMPLE AND SHORT - - [ $cpufreq_source_update -eq 0 ] && . $TMP_DIR/cpufreq.sh $1 + # shellcheck disable=SC1090 + [ $cpufreq_source_update -eq 0 ] && . "$TMP_DIR/cpufreq.sh" "$1" return 0 } diff --git a/charts.d/example.chart.sh b/charts.d/example.chart.sh index 8602ad914e..e4b88d9ef8 100644 --- a/charts.d/example.chart.sh +++ b/charts.d/example.chart.sh @@ -47,7 +47,7 @@ example_get() { example_value4=$((8192 + (RANDOM * 16383 / 32767) )) if [ $example_count -gt 0 ] - then + then example_count=$((example_count - 1)) [ $example_last -gt 16383 ] && example_value4=$((example_last + (RANDOM * ( (32767 - example_last) / 2) / 32767))) @@ -55,8 +55,14 @@ example_get() { else example_count=$((1 + (RANDOM * 5 / 32767) )) - [ $example_last -gt 16383 -a $example_value4 -gt 16383 ] && example_value4=$((example_value4 - 16383)) - [ $example_last -le 16383 -a $example_value4 -lt 16383 ] && example_value4=$((example_value4 + 16383)) + if [ $example_last -gt 16383 ] && [ $example_value4 -gt 16383 ] + then + example_value4=$((example_value4 - 16383)) + fi + if [ $example_last -le 16383 ] && [ $example_value4 -lt 16383 ] + then + example_value4=$((example_value4 + 16383)) + fi fi example_last=$example_value4 diff --git a/charts.d/exim.chart.sh b/charts.d/exim.chart.sh index 996934630b..eb36f329a6 100644 --- a/charts.d/exim.chart.sh +++ b/charts.d/exim.chart.sh @@ -23,7 +23,7 @@ exim_check() { exim_command="${EXIM_CMD}" fi - if [ $(${exim_command} -bpc 2>&1 | grep -c denied) -ne 0 ] + if [ "$(${exim_command} -bpc 2>&1 | grep -c denied)" -ne 0 ] then error "permission denied - please set 'queue_list_requires_admin = false' in your exim options file" return 1 @@ -42,7 +42,7 @@ EOF exim_update() { echo "BEGIN exim_local.qemails $1" - echo "SET emails = " $(run ${exim_command} -bpc) + echo "SET emails = $(run "${exim_command}" -bpc)" echo "END" return 0 } diff --git a/charts.d/hddtemp.chart.sh b/charts.d/hddtemp.chart.sh index 0795db8467..62d74ce051 100644 --- a/charts.d/hddtemp.chart.sh +++ b/charts.d/hddtemp.chart.sh @@ -31,13 +31,14 @@ hddtemp_create() { local all all=$(nc $hddtemp_host $hddtemp_port ) unset hddtemp_disks - hddtemp_disks=( `grep -Po '/dev/[^|]+' <<< "$all" | cut -c 6-` ) + # shellcheck disable=SC2190,SC2207 + hddtemp_disks=( $(grep -Po '/dev/[^|]+' <<< "$all" | cut -c 6-) ) fi # local disk_names # disk_names=(`sed -e 's/||/\n/g;s/^|//' <<< "$all" | cut -d '|' -f2 | tr ' ' '_'`) echo "CHART hddtemp.temperature 'disks_temp' 'temperature' 'Celsius' 'Disks temperature' 'hddtemp.temp' line $((hddtemp_priority)) $hddtemp_update_every" - for i in `seq 0 $((${#hddtemp_disks[@]}-1))`; do + for i in $(seq 0 $((${#hddtemp_disks[@]}-1))); do # echo "DIMENSION ${hddtemp_disks[i]} ${disk_names[i]} absolute 1 1" echo "DIMENSION ${hddtemp_disks[$i]} '' absolute 1 1" done @@ -45,13 +46,14 @@ hddtemp_create() { } # _update is called continuously, to collect the values -hddtemp_last=0 -hddtemp_count=0 +#hddtemp_last=0 +#hddtemp_count=0 hddtemp_update() { # local all=( `nc $hddtemp_host $hddtemp_port | sed -e 's/||/\n/g;s/^|//' | cut -d '|' -f3` ) # local all=( `nc $hddtemp_host $hddtemp_port | awk 'BEGIN { FS="|" };{i=4; while (i <= NF) {print $i+0;i+=5;};}'` ) OLD_IFS=$IFS set -f + # shellcheck disable=SC2207 IFS="|" all=( $(nc $hddtemp_host $hddtemp_port 2>/dev/null) ) set +f IFS=$OLD_IFS |