From a2f1592fe5a1dd286d2ea31f9842c25ac3b280fc Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Thu, 27 Oct 2016 17:49:03 +0200 Subject: [PATCH 1/5] systemd_units: avoid use of temporary file --- plugins/system/systemd_units | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/system/systemd_units b/plugins/system/systemd_units index 4f9ec61c..34563fd3 100755 --- a/plugins/system/systemd_units +++ b/plugins/system/systemd_units @@ -60,14 +60,12 @@ EOF } fetch () { - tmp=$(mktemp -t munin-systemd_units.XXXXXX) - trap "rm \"$tmp\"" EXIT - systemctl --no-pager --no-legend --all | awk '{print $1, $3}' > "$tmp" + tmp=$(systemctl --no-pager --no-legend --all | awk '{print $1, $3}') for state in \ $states ; do echo -n "$state.value " - grep -c "$state$" "$tmp" - extinfo=$(grep "$state$" "$tmp" | cut -d " " -f 1) + echo "$tmp" | grep -c "$state$" + extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1) if [ -n "$extinfo" ]; then echo "$state.extinfo" $extinfo fi From a9476f50fdbe656f601c9616112f2ea3f8b5d7a7 Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Thu, 27 Oct 2016 17:51:33 +0200 Subject: [PATCH 2/5] systemd_units: fix indent --- plugins/system/systemd_units | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/system/systemd_units b/plugins/system/systemd_units index 34563fd3..dd336dd7 100755 --- a/plugins/system/systemd_units +++ b/plugins/system/systemd_units @@ -61,15 +61,14 @@ EOF fetch () { tmp=$(systemctl --no-pager --no-legend --all | awk '{print $1, $3}') - for state in \ - $states ; do - echo -n "$state.value " - echo "$tmp" | grep -c "$state$" - extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1) - if [ -n "$extinfo" ]; then - echo "$state.extinfo" $extinfo - fi -done + for state in $states ; do + echo -n "$state.value " + echo "$tmp" | grep -c "$state$" + extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1) + if [ -n "$extinfo" ]; then + echo "$state.extinfo" $extinfo + fi + done } case $1 in From adc00722860487e663915617caeb60c4388e061d Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Thu, 27 Oct 2016 17:52:30 +0200 Subject: [PATCH 3/5] systemd_units: avoid use of echo -n flag --- plugins/system/systemd_units | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/system/systemd_units b/plugins/system/systemd_units index dd336dd7..0a55adc5 100755 --- a/plugins/system/systemd_units +++ b/plugins/system/systemd_units @@ -62,8 +62,8 @@ EOF fetch () { tmp=$(systemctl --no-pager --no-legend --all | awk '{print $1, $3}') for state in $states ; do - echo -n "$state.value " - echo "$tmp" | grep -c "$state$" + count=$(echo "$tmp" | grep -c "$state$") + echo "$state.value $count" extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1) if [ -n "$extinfo" ]; then echo "$state.extinfo" $extinfo From 38835f7a62111ebdbc3ea91a47ee2174e7d225f6 Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Thu, 27 Oct 2016 17:54:01 +0200 Subject: [PATCH 4/5] systemd_units: add doublequote around $extinfo --- plugins/system/systemd_units | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/system/systemd_units b/plugins/system/systemd_units index 0a55adc5..e7f3960f 100755 --- a/plugins/system/systemd_units +++ b/plugins/system/systemd_units @@ -64,9 +64,9 @@ fetch () { for state in $states ; do count=$(echo "$tmp" | grep -c "$state$") echo "$state.value $count" - extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1) + extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1 | tr -d '\n') if [ -n "$extinfo" ]; then - echo "$state.extinfo" $extinfo + echo "$state.extinfo" "$extinfo" fi done } From d888c31d1d9ce2a997bc43e0d90baad31e6a0c7c Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Thu, 27 Oct 2016 18:19:16 +0200 Subject: [PATCH 5/5] systemd_units: fix use of tr --- plugins/system/systemd_units | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/systemd_units b/plugins/system/systemd_units index e7f3960f..33e59115 100755 --- a/plugins/system/systemd_units +++ b/plugins/system/systemd_units @@ -64,7 +64,7 @@ fetch () { for state in $states ; do count=$(echo "$tmp" | grep -c "$state$") echo "$state.value $count" - extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1 | tr -d '\n') + extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1 | tr '\n' ' ') if [ -n "$extinfo" ]; then echo "$state.extinfo" "$extinfo" fi