From 0c7f3692a39737c8ad6ac2f85197268f6f488b76 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Fri, 4 Mar 2016 11:52:45 +1300 Subject: Get rid of some warnings in shellchecker --- minimunin | 66 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/minimunin b/minimunin index 98325f6..ada2a3e 100755 --- a/minimunin +++ b/minimunin @@ -13,19 +13,19 @@ SYSCTL=/sbin/sysctl [ -f ${SYSCTL} ] || SYSCTL=/usr/sbin/sysctl # list plugins, read configs -PLUGINS=`/usr/bin/find ${PLUGIN_DIR} \( -type l -or -type f \) -not -name *_ -perm +111 -exec basename {} \; 2> /dev/null | /usr/bin/xargs` -CONFIGS=`/usr/bin/find ${CONFIG_DIR} -type f -exec /usr/bin/grep -v -e ^\# -e ^$ {} \; -exec /bin/echo [] \; 2> /dev/null` +PLUGINS=$(/usr/bin/find ${PLUGIN_DIR} \( -type l -or -type f \) -not -name '*_' -perm +111 -exec basename {} \; 2> /dev/null | /usr/bin/xargs) +CONFIGS=$(/usr/bin/find ${CONFIG_DIR} -type f -exec /usr/bin/grep -v -e ^\# -e ^$ {} \; -exec /bin/echo [] \; 2> /dev/null) main() { # print banner - printf "# munin node at %s\n" `/bin/hostname` + printf "# munin node at %s\n" "$(/bin/hostname)" # read commands in loop - while read command arg; do + while read -r command arg; do # chomp and sanitize variables - command=`printf %s "${command}" | /usr/bin/tr -cd '[:alnum:]_-. '` - arg=`printf %s "${arg}" | /usr/bin/tr -cd '[:alnum:]_-. '` + command=$(printf %s "${command}" | /usr/bin/tr -cd '[:alnum:]_-. ') + arg=$(printf %s "${arg}" | /usr/bin/tr -cd '[:alnum:]_-. ') # printf "%s %s\n" "$command" "$arg" >> /var/log/minimunin.log # dispatch commands @@ -43,7 +43,7 @@ main() { exit 0 ;; *) - printf "# Unknown command ${command}.\n" + printf "# Unknown command %s.\n" "${command}" # printf %s ${command} | hexdump -C >> /var/log/minimunin.log ;; esac @@ -58,22 +58,22 @@ call_plugin ${_plugin} fetch && return 0 # if not, let our builtins answer case ${_plugin} in open_files) - printf "max.value %d\n" `get_sys kern.maxfiles` - printf "used.value %d\n" `get_sys kern.openfiles` + printf "max.value %d\n" $(get_sys kern.maxfiles) + printf "used.value %d\n" $(get_sys kern.openfiles) ;; load) - printf "load.value %s\n" `get_sys vm.loadavg | /usr/bin/cut -f3 -d ' '` + printf "load.value %s\n" $(get_sys vm.loadavg | /usr/bin/cut -f3 -d ' ') ;; swap) - printf "swap_in.value %d\n" `get_sys vm.stats.vm.v_swappgsin` - printf "swap_out.value %d\n" `get_sys vm.stats.vm.v_swappgsout` + printf "swap_in.value %d\n" $(get_sys vm.stats.vm.v_swappgsin) + printf "swap_out.value %d\n" $(get_sys vm.stats.vm.v_swappgsout) ;; uptime) - boot=`get_sys kern.boottime`; boot=${boot#*sec =}; boot=${boot%%,*} + boot=$(get_sys kern.boottime); boot=${boot#*sec =}; boot=${boot%%,*} printf "uptime.value %d\n" $(( ( `/bin/date +%s` - boot ) / 86400 )) ;; memory) - pagesize=`get_sys vm.stats.vm.v_page_size` + pagesize=$(get_sys vm.stats.vm.v_page_size) printf "active.value %d\n" $(( pagesize * `get_sys vm.stats.vm.v_active_count` )) printf "inactive.value %d\n" $(( pagesize * `get_sys vm.stats.vm.v_inactive_count` )) printf "wired.value %d\n" $(( pagesize * `get_sys vm.stats.vm.v_wire_count` )) @@ -83,33 +83,33 @@ memory) printf "swap.value %d\n" $(( `/usr/sbin/swapinfo -k | /usr/bin/tail -n 1 | /usr/bin/xargs | /usr/bin/cut -d ' ' -f 3` * 1024 )) ;; cpu) - set -- `get_sys kern.cp_time` + set -- $(get_sys kern.cp_time) printf "user.value %d\nnice.value %d\nsystem.value %d\ninterrupt.value %d\nidle.value %d\n" "$1" "$2" "$3" "$4" "$5" ;; processes) - printf "processes.value %d\n" `/bin/pgrep -aS .* | /usr/bin/wc -l` + printf "processes.value %d\n" $(/bin/pgrep -aS .* | /usr/bin/wc -l) printf "threads.value %d\n" $(( `ps auxwH | wc -l` - 1 )) - printf "maxprocesses.value %d\n" `get_sys kern.maxproc` + printf "maxprocesses.value %d\n" $(get_sys kern.maxproc) ;; iostat) - for d in `/usr/sbin/iostat -Id | /usr/bin/head -n 1 | /usr/bin/xargs`; do - set -- `/usr/sbin/iostat -Idx ${d} | /usr/bin/tail -n 1 | /usr/bin/xargs` + for d in $(/usr/sbin/iostat -Id | /usr/bin/head -n 1 | /usr/bin/xargs); do + set -- $(/usr/sbin/iostat -Idx ${d} | /usr/bin/tail -n 1 | /usr/bin/xargs) printf "${d}_read.value %d\n${d}_write.value %d\n" "${4%.*}" "${5%.*}" done ;; systat) - set -- `get_sys vm.stats.sys.v_soft vm.stats.sys.v_intr vm.stats.sys.v_syscall vm.stats.sys.v_swtch vm.stats.vm.v_forks vm.stats.vm.v_rforks vm.stats.vm.v_vforks` + set -- $(get_sys vm.stats.sys.v_soft vm.stats.sys.v_intr vm.stats.sys.v_syscall vm.stats.sys.v_swtch vm.stats.vm.v_forks vm.stats.vm.v_rforks vm.stats.vm.v_vforks) printf "softint.value %d\nhardint.value %d\nsyscall.value %d\ncs.value %d\nforks.value %d\n" "$1" "$2" "$3" "$4" $(( ${5}+${6}+${7} )) ;; df) /bin/df -P -t noprocfs,devfs,fdescfs,linprocfs,linsysfs,nfs,nullfs | /usr/bin/tail -n +2 | - while read fs blocks used avail cap mount; do - fs=`printf "%s" ${fs} | /usr/bin/tr -c '[:alnum:]' _` - printf "%s %d\n" ${fs}.value $(( used * 512 )) + while read -r fs blocks used avail cap mount; do + fs=$(printf "%s" ${fs} | /usr/bin/tr -c '[:alnum:]' _) + printf "%s %d\n" "${fs}.value" $(( used * 512 )) done ;; *) - printf "# Unknown plugin ${_plugin}.\n" + printf "# Unknown plugin %s.\n" "${_plugin}" ;; esac } @@ -155,7 +155,7 @@ cat <<-EOF EOF ;; iostat) - drives=`/usr/sbin/iostat -Id | /usr/bin/head -n 1 | /usr/bin/xargs` + drives=$(/usr/sbin/iostat -Id | /usr/bin/head -n 1 | /usr/bin/xargs) cat <<-EOF graph_title IOstat by bytes graph_args --base 1024 -l 0 @@ -164,7 +164,7 @@ cat <<-EOF graph_info This graph shows the I/O to and from block devices EOF printf "graph_order" -for d in ${drives}; do printf " %s_read %s_write" $d $d; done +for d in ${drives}; do printf " %s_read %s_write" "$d" "$d"; done printf "\n" for d in ${drives}; do cat <<-EOF @@ -332,13 +332,13 @@ cat <<-EOF graph_category disk EOF /bin/df -P -t noprocfs,devfs,fdescfs,linprocfs,linsysfs,nfs,nullfs | /usr/bin/tail -n +2 | -while read fs blocks used avail cap mount; do - fs=`printf "%s" ${fs} | /usr/bin/tr -c '[:alnum:]' _` - printf "%s %s\n" ${fs}.label ${mount} +while read -r fs blocks used avail cap mount; do + fs=$(printf "%s" ${fs} | /usr/bin/tr -c '[:alnum:]' _) + printf "%s %s\n" "${fs}.label" "${mount}" done ;; *) - printf "# Unknown plugin ${_plugin}.\n" + printf "# Unknown plugin %s.\n" "${_plugin}" ;; esac } @@ -349,11 +349,11 @@ get_sys() { call_plugin() { _param=$2 - _plug=`/usr/bin/find ${PLUGIN_DIR} \( -type l -or -type f \) -perm +111 -name $1 2>/dev/null | /usr/bin/head -n 1` + _plug=$(/usr/bin/find ${PLUGIN_DIR} \( -type l -or -type f \) -perm +111 -name "$1" 2>/dev/null | /usr/bin/head -n 1) [ -z "${_plug}" ] && return 1 unset in_sect _env _user _command - while read line; do + while read -r line; do case ${line## } in \[*\]) case [$1 in ${line%%]*}) in_sect=true;; *) unset in_sect ;; esac ;; @@ -383,7 +383,7 @@ EOF _command="${_command} ${_param}" # if we're required to switch the user and able to do so (root) use su to become this user - [ "${_user}" -a `id -u` -eq 0 ] && _command="/usr/bin/su -m ${_user} -c '${_command}'" + [ "${_user}" ] && [ $(id -u) -eq 0 ] && _command="/usr/bin/su -m ${_user} -c '${_command}'" # prepend environment and run the command eval env ${_env} ${_command} -- cgit v1.2.3