From 3cfa884a6fae30023a98e7e8a331664f2239bbde Mon Sep 17 00:00:00 2001 From: Victor LABORIE Date: Wed, 16 Jan 2019 16:53:53 +0100 Subject: [PATCH 1/3] Add a verbose function and use it for some checks (Fix #30) --- evocheck.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/evocheck.sh b/evocheck.sh index 1af4599..f9a8aeb 100755 --- a/evocheck.sh +++ b/evocheck.sh @@ -125,9 +125,17 @@ IS_NRPEDAEMON=1 IS_ALERTBOOT=1 IS_RSYNC=1 +# Verbose function +verbose() { + msg="${1:-$(cat /dev/stdin)}" + [ "${VERBOSE}" -eq 1 ] && echo "${msg}" +} + # Source configuration file test -f /etc/evocheck.cf && . /etc/evocheck.cf +VERBOSE="${VERBOSE:-0}" + # If --cron is passed, ignore some checks. if [ "$1" = "--cron" ]; then IS_KERNELUPTODATE=0 @@ -553,11 +561,7 @@ if [ -e /etc/debian_version ]; then percentage=$(python -c "print(int(round(float(${reservedBlockCount})/${blockCount}*100)))") if [ "$percentage" -lt 5 ]; then echo 'IS_TUNE2FS_M5 FAILED!' - # Set debug to 1, to displays which partitions has less than 5% - debug=0 - if [ "$debug" -eq 1 ]; then - echo "Partition $part has less than 5% reserved blocks!" - fi + verbose "Partition $part has less than 5% reserved blocks!" fi done fi @@ -840,7 +844,7 @@ if [ -e /etc/debian_version ]; then if [ "$IS_OLD_HOME_DIR" = 1 ]; then for dir in /home/*; do - stat -c "%n has owner %u resolved as %U" "$dir" | grep -v .bak | grep -q UNKNOWN + stat -c "%n has owner %u resolved as %U" "$dir" | grep -v .bak | grep UNKNOWN | verbose if [[ ${PIPESTATUS[2]} == 0 ]]; then # There is at least one dir matching echo 'IS_OLD_HOME_DIR FAILED!' From 6bfe6eb9a749206e32c6517254587cf77f1c78a1 Mon Sep 17 00:00:00 2001 From: Victor LABORIE Date: Thu, 17 Jan 2019 11:02:40 +0100 Subject: [PATCH 2/3] Fix odd return line in verbose mode --- evocheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evocheck.sh b/evocheck.sh index f9a8aeb..87567b0 100755 --- a/evocheck.sh +++ b/evocheck.sh @@ -128,7 +128,7 @@ IS_RSYNC=1 # Verbose function verbose() { msg="${1:-$(cat /dev/stdin)}" - [ "${VERBOSE}" -eq 1 ] && echo "${msg}" + [ "${VERBOSE}" -eq 1 ] && [ -n "${msg}" ] && echo "${msg}" } # Source configuration file From 671bdbd92b030081d422f27384ffacc27e753a1e Mon Sep 17 00:00:00 2001 From: Victor LABORIE Date: Thu, 17 Jan 2019 11:28:34 +0100 Subject: [PATCH 3/3] Rewrite IS_OLD_HOME_DIR with find (fix output order in verbose mode) --- evocheck.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/evocheck.sh b/evocheck.sh index 87567b0..a825350 100755 --- a/evocheck.sh +++ b/evocheck.sh @@ -843,14 +843,8 @@ if [ -e /etc/debian_version ]; then fi if [ "$IS_OLD_HOME_DIR" = 1 ]; then - for dir in /home/*; do - stat -c "%n has owner %u resolved as %U" "$dir" | grep -v .bak | grep UNKNOWN | verbose - if [[ ${PIPESTATUS[2]} == 0 ]]; then - # There is at least one dir matching - echo 'IS_OLD_HOME_DIR FAILED!' - break - fi - done + find /home/ -maxdepth 1 -type d -nouser | grep -q '^' && echo 'IS_OLD_HOME_DIR FAILED!' + [ "${VERBOSE}" -eq 1 ] && find /home/ -maxdepth 1 -type d -nouser -exec stat -c "%n has owner %u resolved as %U" {} \; fi fi