summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2016-03-04 11:52:45 +1300
committerDirk Engling <erdgeist@erdgeist.org>2016-03-04 11:52:45 +1300
commit0c7f3692a39737c8ad6ac2f85197268f6f488b76 (patch)
treed130db4c17e1161d30df4cb9704c017e9777978b
parentf3e42da230b1d457ff8b3e54ba4b9b3893779296 (diff)
Get rid of some warnings in shellchecker
-rwxr-xr-xminimunin66
1 files 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
13[ -f ${SYSCTL} ] || SYSCTL=/usr/sbin/sysctl 13[ -f ${SYSCTL} ] || SYSCTL=/usr/sbin/sysctl
14 14
15# list plugins, read configs 15# list plugins, read configs
16PLUGINS=`/usr/bin/find ${PLUGIN_DIR} \( -type l -or -type f \) -not -name *_ -perm +111 -exec basename {} \; 2> /dev/null | /usr/bin/xargs` 16PLUGINS=$(/usr/bin/find ${PLUGIN_DIR} \( -type l -or -type f \) -not -name '*_' -perm +111 -exec basename {} \; 2> /dev/null | /usr/bin/xargs)
17CONFIGS=`/usr/bin/find ${CONFIG_DIR} -type f -exec /usr/bin/grep -v -e ^\# -e ^$ {} \; -exec /bin/echo [] \; 2> /dev/null` 17CONFIGS=$(/usr/bin/find ${CONFIG_DIR} -type f -exec /usr/bin/grep -v -e ^\# -e ^$ {} \; -exec /bin/echo [] \; 2> /dev/null)
18 18
19main() { 19main() {
20 # print banner 20 # print banner
21 printf "# munin node at %s\n" `/bin/hostname` 21 printf "# munin node at %s\n" "$(/bin/hostname)"
22 22
23 # read commands in loop 23 # read commands in loop
24 while read command arg; do 24 while read -r command arg; do
25 25
26 # chomp and sanitize variables 26 # chomp and sanitize variables
27 command=`printf %s "${command}" | /usr/bin/tr -cd '[:alnum:]_-. '` 27 command=$(printf %s "${command}" | /usr/bin/tr -cd '[:alnum:]_-. ')
28 arg=`printf %s "${arg}" | /usr/bin/tr -cd '[:alnum:]_-. '` 28 arg=$(printf %s "${arg}" | /usr/bin/tr -cd '[:alnum:]_-. ')
29 29
30 # printf "%s %s\n" "$command" "$arg" >> /var/log/minimunin.log 30 # printf "%s %s\n" "$command" "$arg" >> /var/log/minimunin.log
31 # dispatch commands 31 # dispatch commands
@@ -43,7 +43,7 @@ main() {
43 exit 0 43 exit 0
44 ;; 44 ;;
45 *) 45 *)
46 printf "# Unknown command ${command}.\n" 46 printf "# Unknown command %s.\n" "${command}"
47 # printf %s ${command} | hexdump -C >> /var/log/minimunin.log 47 # printf %s ${command} | hexdump -C >> /var/log/minimunin.log
48 ;; 48 ;;
49 esac 49 esac
@@ -58,22 +58,22 @@ call_plugin ${_plugin} fetch && return 0
58# if not, let our builtins answer 58# if not, let our builtins answer
59case ${_plugin} in 59case ${_plugin} in
60open_files) 60open_files)
61 printf "max.value %d\n" `get_sys kern.maxfiles` 61 printf "max.value %d\n" $(get_sys kern.maxfiles)
62 printf "used.value %d\n" `get_sys kern.openfiles` 62 printf "used.value %d\n" $(get_sys kern.openfiles)
63 ;; 63 ;;
64load) 64load)
65 printf "load.value %s\n" `get_sys vm.loadavg | /usr/bin/cut -f3 -d ' '` 65 printf "load.value %s\n" $(get_sys vm.loadavg | /usr/bin/cut -f3 -d ' ')
66 ;; 66 ;;
67swap) 67swap)
68 printf "swap_in.value %d\n" `get_sys vm.stats.vm.v_swappgsin` 68 printf "swap_in.value %d\n" $(get_sys vm.stats.vm.v_swappgsin)
69 printf "swap_out.value %d\n" `get_sys vm.stats.vm.v_swappgsout` 69 printf "swap_out.value %d\n" $(get_sys vm.stats.vm.v_swappgsout)
70 ;; 70 ;;
71uptime) 71uptime)
72 boot=`get_sys kern.boottime`; boot=${boot#*sec =}; boot=${boot%%,*} 72 boot=$(get_sys kern.boottime); boot=${boot#*sec =}; boot=${boot%%,*}
73 printf "uptime.value %d\n" $(( ( `/bin/date +%s` - boot ) / 86400 )) 73 printf "uptime.value %d\n" $(( ( `/bin/date +%s` - boot ) / 86400 ))
74 ;; 74 ;;
75memory) 75memory)
76 pagesize=`get_sys vm.stats.vm.v_page_size` 76 pagesize=$(get_sys vm.stats.vm.v_page_size)
77 printf "active.value %d\n" $(( pagesize * `get_sys vm.stats.vm.v_active_count` )) 77 printf "active.value %d\n" $(( pagesize * `get_sys vm.stats.vm.v_active_count` ))
78 printf "inactive.value %d\n" $(( pagesize * `get_sys vm.stats.vm.v_inactive_count` )) 78 printf "inactive.value %d\n" $(( pagesize * `get_sys vm.stats.vm.v_inactive_count` ))
79 printf "wired.value %d\n" $(( pagesize * `get_sys vm.stats.vm.v_wire_count` )) 79 printf "wired.value %d\n" $(( pagesize * `get_sys vm.stats.vm.v_wire_count` ))
@@ -83,33 +83,33 @@ memory)
83 printf "swap.value %d\n" $(( `/usr/sbin/swapinfo -k | /usr/bin/tail -n 1 | /usr/bin/xargs | /usr/bin/cut -d ' ' -f 3` * 1024 )) 83 printf "swap.value %d\n" $(( `/usr/sbin/swapinfo -k | /usr/bin/tail -n 1 | /usr/bin/xargs | /usr/bin/cut -d ' ' -f 3` * 1024 ))
84 ;; 84 ;;
85cpu) 85cpu)
86 set -- `get_sys kern.cp_time` 86 set -- $(get_sys kern.cp_time)
87 printf "user.value %d\nnice.value %d\nsystem.value %d\ninterrupt.value %d\nidle.value %d\n" "$1" "$2" "$3" "$4" "$5" 87 printf "user.value %d\nnice.value %d\nsystem.value %d\ninterrupt.value %d\nidle.value %d\n" "$1" "$2" "$3" "$4" "$5"
88 ;; 88 ;;
89processes) 89processes)
90 printf "processes.value %d\n" `/bin/pgrep -aS .* | /usr/bin/wc -l` 90 printf "processes.value %d\n" $(/bin/pgrep -aS .* | /usr/bin/wc -l)
91 printf "threads.value %d\n" $(( `ps auxwH | wc -l` - 1 )) 91 printf "threads.value %d\n" $(( `ps auxwH | wc -l` - 1 ))
92 printf "maxprocesses.value %d\n" `get_sys kern.maxproc` 92 printf "maxprocesses.value %d\n" $(get_sys kern.maxproc)
93 ;; 93 ;;
94iostat) 94iostat)
95 for d in `/usr/sbin/iostat -Id | /usr/bin/head -n 1 | /usr/bin/xargs`; do 95 for d in $(/usr/sbin/iostat -Id | /usr/bin/head -n 1 | /usr/bin/xargs); do
96 set -- `/usr/sbin/iostat -Idx ${d} | /usr/bin/tail -n 1 | /usr/bin/xargs` 96 set -- $(/usr/sbin/iostat -Idx ${d} | /usr/bin/tail -n 1 | /usr/bin/xargs)
97 printf "${d}_read.value %d\n${d}_write.value %d\n" "${4%.*}" "${5%.*}" 97 printf "${d}_read.value %d\n${d}_write.value %d\n" "${4%.*}" "${5%.*}"
98 done 98 done
99 ;; 99 ;;
100systat) 100systat)
101 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` 101 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)
102 printf "softint.value %d\nhardint.value %d\nsyscall.value %d\ncs.value %d\nforks.value %d\n" "$1" "$2" "$3" "$4" $(( ${5}+${6}+${7} )) 102 printf "softint.value %d\nhardint.value %d\nsyscall.value %d\ncs.value %d\nforks.value %d\n" "$1" "$2" "$3" "$4" $(( ${5}+${6}+${7} ))
103 ;; 103 ;;
104df) 104df)
105 /bin/df -P -t noprocfs,devfs,fdescfs,linprocfs,linsysfs,nfs,nullfs | /usr/bin/tail -n +2 | 105 /bin/df -P -t noprocfs,devfs,fdescfs,linprocfs,linsysfs,nfs,nullfs | /usr/bin/tail -n +2 |
106 while read fs blocks used avail cap mount; do 106 while read -r fs blocks used avail cap mount; do
107 fs=`printf "%s" ${fs} | /usr/bin/tr -c '[:alnum:]' _` 107 fs=$(printf "%s" ${fs} | /usr/bin/tr -c '[:alnum:]' _)
108 printf "%s %d\n" ${fs}.value $(( used * 512 )) 108 printf "%s %d\n" "${fs}.value" $(( used * 512 ))
109 done 109 done
110 ;; 110 ;;
111*) 111*)
112 printf "# Unknown plugin ${_plugin}.\n" 112 printf "# Unknown plugin %s.\n" "${_plugin}"
113 ;; 113 ;;
114esac 114esac
115} 115}
@@ -155,7 +155,7 @@ cat <<-EOF
155EOF 155EOF
156;; 156;;
157iostat) 157iostat)
158 drives=`/usr/sbin/iostat -Id | /usr/bin/head -n 1 | /usr/bin/xargs` 158 drives=$(/usr/sbin/iostat -Id | /usr/bin/head -n 1 | /usr/bin/xargs)
159cat <<-EOF 159cat <<-EOF
160 graph_title IOstat by bytes 160 graph_title IOstat by bytes
161 graph_args --base 1024 -l 0 161 graph_args --base 1024 -l 0
@@ -164,7 +164,7 @@ cat <<-EOF
164 graph_info This graph shows the I/O to and from block devices 164 graph_info This graph shows the I/O to and from block devices
165EOF 165EOF
166 printf "graph_order" 166 printf "graph_order"
167for d in ${drives}; do printf " %s_read %s_write" $d $d; done 167for d in ${drives}; do printf " %s_read %s_write" "$d" "$d"; done
168 printf "\n" 168 printf "\n"
169for d in ${drives}; do 169for d in ${drives}; do
170 cat <<-EOF 170 cat <<-EOF
@@ -332,13 +332,13 @@ cat <<-EOF
332 graph_category disk 332 graph_category disk
333EOF 333EOF
334/bin/df -P -t noprocfs,devfs,fdescfs,linprocfs,linsysfs,nfs,nullfs | /usr/bin/tail -n +2 | 334/bin/df -P -t noprocfs,devfs,fdescfs,linprocfs,linsysfs,nfs,nullfs | /usr/bin/tail -n +2 |
335while read fs blocks used avail cap mount; do 335while read -r fs blocks used avail cap mount; do
336 fs=`printf "%s" ${fs} | /usr/bin/tr -c '[:alnum:]' _` 336 fs=$(printf "%s" ${fs} | /usr/bin/tr -c '[:alnum:]' _)
337 printf "%s %s\n" ${fs}.label ${mount} 337 printf "%s %s\n" "${fs}.label" "${mount}"
338done 338done
339;; 339;;
340*) 340*)
341 printf "# Unknown plugin ${_plugin}.\n" 341 printf "# Unknown plugin %s.\n" "${_plugin}"
342 ;; 342 ;;
343esac 343esac
344} 344}
@@ -349,11 +349,11 @@ get_sys() {
349 349
350call_plugin() { 350call_plugin() {
351 _param=$2 351 _param=$2
352 _plug=`/usr/bin/find ${PLUGIN_DIR} \( -type l -or -type f \) -perm +111 -name $1 2>/dev/null | /usr/bin/head -n 1` 352 _plug=$(/usr/bin/find ${PLUGIN_DIR} \( -type l -or -type f \) -perm +111 -name "$1" 2>/dev/null | /usr/bin/head -n 1)
353 [ -z "${_plug}" ] && return 1 353 [ -z "${_plug}" ] && return 1
354 354
355 unset in_sect _env _user _command 355 unset in_sect _env _user _command
356 while read line; do 356 while read -r line; do
357 case ${line## } in 357 case ${line## } in
358 \[*\]) case [$1 in ${line%%]*}) in_sect=true;; *) unset in_sect ;; esac 358 \[*\]) case [$1 in ${line%%]*}) in_sect=true;; *) unset in_sect ;; esac
359 ;; 359 ;;
@@ -383,7 +383,7 @@ EOF
383 _command="${_command} ${_param}" 383 _command="${_command} ${_param}"
384 384
385 # if we're required to switch the user and able to do so (root) use su to become this user 385 # if we're required to switch the user and able to do so (root) use su to become this user
386 [ "${_user}" -a `id -u` -eq 0 ] && _command="/usr/bin/su -m ${_user} -c '${_command}'" 386 [ "${_user}" ] && [ $(id -u) -eq 0 ] && _command="/usr/bin/su -m ${_user} -c '${_command}'"
387 387
388 # prepend environment and run the command 388 # prepend environment and run the command
389 eval env ${_env} ${_command} 389 eval env ${_env} ${_command}