2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Double quote to prevent globbing and word splitting

https://github.com/koalaman/shellcheck/wiki/SC2086
This commit is contained in:
Nils 2018-02-22 12:38:25 +01:00
parent 15125852e8
commit 5c08e0744c

View File

@ -72,7 +72,7 @@ nvSmiExec=${smiexec:-'/usr/bin/nvidia-smi'}
# Check if autoconf was requested
if [ "$1" = "autoconf" ]; then
# Autoconf only returns yes if nvidia-smi exists and is executable
if [ -x $nvSmiExec ]; then
if [ -x "$nvSmiExec" ]; then
echo yes
exit 0
else
@ -93,7 +93,7 @@ fi
# Get number of GPUs
nGpusOutput=$($nvSmiExec -L)
nGpus=$(echo "$nGpusOutput" | wc -l)
if [ $nGpus -eq 0 ]; then
if [ "$nGpus" -eq 0 ]; then
# Exit if no GPUs found
echo "No NVIDIA GPUs detected. Exiting."
exit 1
@ -117,7 +117,7 @@ if [ "$1" = "config" ]; then
echo 'graph_category sensors'
echo "graph_info Temperature information for NVIDIA GPUs using driver version $driverVersion"
nGpusCounter=0
while [ $nGpusCounter -lt $nGpus ]
while [ "$nGpusCounter" -lt "$nGpus" ]
do
gpuName=$(echo "$nGpusOutput" | sed -n $((nGpusCounter+1))p | cut -d \( -f 1)
echo "temp${nGpusCounter}.warning ${warning:-75}"
@ -131,14 +131,14 @@ if [ "$1" = "config" ]; then
gpusTotalMemOutput=$(echo "$smiOutput" | grep -v BAR1 | grep -A 3 "Memory Usage" | grep "Total" | cut -d : -f 2 | tr -d ' ')
gpusTotalMem=''
nGpusCounter=0
while [ $nGpusCounter -lt $nGpus ]
while [ "$nGpusCounter" -lt "$nGpus" ]
do
gpuName=$(echo "$nGpusOutput" | sed -n $((nGpusCounter+1))p | cut -d \( -f 1)
echo "mem${nGpusCounter}.info Memory information for $gpuName"
gpuMem=$(echo "$gpusTotalMemOutput"| sed -n $((nGpusCounter+1))p)
gpusTotalMem="${gpusTotalMem}${gpuMem} for GPU ${nGpusCounter}"
: $((nGpusCounter=nGpusCounter+1))
if [ $nGpusCounter -lt $nGpus ]; then
if [ "$nGpusCounter" -lt "$nGpus" ]; then
gpusTotalMem="${gpusTotalMem}, "
fi
done
@ -156,7 +156,7 @@ if [ "$1" = "config" ]; then
echo 'graph_category sensors'
echo "graph_info Fan speed of NVIDIA GPUs using driver version $driverVersion"
nGpusCounter=0
while [ $nGpusCounter -lt $nGpus ]
while [ "$nGpusCounter" -lt "$nGpus" ]
do
gpuName=$(echo "$nGpusOutput" | sed -n $((nGpusCounter+1))p | cut -d \( -f 1)
echo "fan${nGpusCounter}.info Fan information for $gpuName"
@ -169,7 +169,7 @@ if [ "$1" = "config" ]; then
echo 'graph_category sensors'
echo "graph_info power consumption of NVIDIA GPUs using driver version $driverVersion"
nGpusCounter=0
while [ $nGpusCounter -lt $nGpus ]
while [ "$nGpusCounter" -lt "$nGpus" ]
do
gpuName=$(echo "$nGpusOutput" | sed -n $((nGpusCounter+1))p | cut -d \( -f 1)
echo "power${nGpusCounter}.info power consumption of $gpuName"
@ -185,7 +185,7 @@ if [ "$1" = "config" ]; then
# Common stuff for all quantities
nGpusCounter=0
while [ $nGpusCounter -lt $nGpus ]
while [ "$nGpusCounter" -lt "$nGpus" ]
do
gpuName=$(echo "$nGpusOutput" | sed -n $((nGpusCounter+1))p | cut -d \( -f 1)
echo "${name}${nGpusCounter}.label $gpuName"
@ -207,7 +207,7 @@ case $name in
usedMemGpus=$(echo "$smiOutput" | grep -v BAR1 | grep -A 3 "Memory Usage" | grep "Used" | cut -d : -f 2 | cut -d ' ' -f 2)
valueGpus=''
nGpusCounter=0
while [ $nGpusCounter -lt $nGpus ]
while [ "$nGpusCounter" -lt "$nGpus" ]
do
totalMemGpu=$(echo "$totalMemGpus" | sed -n $((nGpusCounter+1))p)
usedMemGpu=$(echo "$usedMemGpus" | sed -n $((nGpusCounter+1))p)
@ -232,7 +232,7 @@ case $name in
# Print requested value
nGpusCounter=0
while [ $nGpusCounter -lt $nGpus ]
while [ "$nGpusCounter" -lt "$nGpus" ]
do
value=$(echo "$valueGpus" | sed -n $((nGpusCounter+1))p)
echo "${name}${nGpusCounter}.value $value"