From 02f41b360356447231b6016f03f34da0bf841c83 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Mon, 10 Feb 2025 17:34:26 +0100 Subject: [PATCH] check_conn: no text on STDERR if portcheck fails --- check_conn | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/check_conn b/check_conn index 7848798..efab1fe 100755 --- a/check_conn +++ b/check_conn @@ -9,16 +9,13 @@ # ---------------------------------------------------------------------- # 2021-11-05 v0.0 <axel.hahn@iml.unibe.ch> # 2023-07-27 v1.1 <axel.hahn@unibe.ch> update help page +# 2025-02-10 v1.2 <axel.hahn@unibe.ch> no text on STDERR if portcheck fails # ====================================================================== -. $(dirname $0)/inc_pluginfunctions - -export self_APPVERSION=1.1 - +. $(dirname $0)/inc_pluginfunctions || exit 1 +export self_APPVERSION=1.2 cfgfile=$( dirname $0 )/$( basename $0 ).cfg - - out="" # ---------------------------------------------------------------------- @@ -87,12 +84,9 @@ case "$1" in *) esac -configline=$( ph.getValueWithParam "" t "$@" ) - +configline=$( ph.getValueWithParam "" t "$@" test -z "$configline" || cfgfile="" - - typeset -i iWarnings=0 typeset -i iErrors=0 typeset -i iOK=0 @@ -107,18 +101,18 @@ do $myline" # --- syntax check of config entry - echo "$myline" | grep -E "^(tcp|udp)/[a-z][a-z0-9\.\-]*/[0-9]*$" >/dev/null 2>&1 - if [ $? -ne 0 ]; then + if ! echo "$myline" | grep -Eq "^(tcp|udp)/[a-z][a-z0-9\.\-]*/[0-9]*$" + then out="$out SKIP: INVALID ENTRY" iWarnings=$iWarnings+1 else - >/dev/$myline - if [ $? -ne 0 ]; then - out="$out FAILED" - iErrors=$iErrors+1 - else + if timeout 1 bash -c "> /dev/$myline " 2>/dev/null + then out="$out OK" iOK=$iOK+1 + else + out="$out FAILED" + iErrors=$iErrors+1 fi fi done -- GitLab