From 8ffac20d8e5668bcbff46330456a8341f3d9b08c Mon Sep 17 00:00:00 2001 From: Jens Maus Date: Tue, 18 Jun 2019 08:54:12 +0200 Subject: [PATCH] fixed "timeout" wrapper script to correctly replicate the BusyBox 'timeout' command syntax where the time to wait is supplied via a second argument rather than a "-t" option. --- addon/addon/server.tcl | 12 ++++++------ addon/addon/timeout | 7 +++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/addon/addon/server.tcl b/addon/addon/server.tcl index c1fa117..682b52f 100755 --- a/addon/addon/server.tcl +++ b/addon/addon/server.tcl @@ -34,10 +34,10 @@ proc handle_connection { channelId clientAddress clientPort } { if { [file exists /proc/net/tcp6] == 1 } { puts $channelId "<<>>" - puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout -s 1 -t 10 cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | awk { /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } } }]" + puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout -s 1 10 cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | awk { /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } } }]" } else { puts $channelId "<<>>" - puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout -s 1 -t 10 cat /proc/net/tcp 2>/dev/null | awk { /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } } }]" + puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout -s 1 10 cat /proc/net/tcp 2>/dev/null | awk { /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } } }]" } puts $channelId "<<>>" @@ -67,10 +67,10 @@ proc handle_connection { channelId clientAddress clientPort } { if { [file exists /bin/stat] == 1 } { puts $channelId "<<>>" - puts $channelId [exec sh -c {sed -n '/ nfs4\? /s/[^ ]* \([^ ]*\) .*/\1/p' >>" - puts $channelId [exec sh -c {sed -n '/ cifs\? /s/[^ ]* \([^ ]*\) .*/\1/p' >>" @@ -82,12 +82,12 @@ proc handle_connection { channelId clientAddress clientPort } { if { [file exists /usr/bin/ntpq] == 1 } { puts $channelId "<<>>" - puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout -t 5 /usr/bin/ntpq -np | sed -e 1,2d -e {s/^\(.\)/\1 /} -e {s/^ /%/}]" + puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout 5 /usr/bin/ntpq -np | sed -e 1,2d -e {s/^\(.\)/\1 /} -e {s/^ /%/}]" } if { [file exists /usr/bin/chronyc] == 1 } { puts $channelId "<<>>" - puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout -t 5 /usr/bin/chronyc -n tracking]" + puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout 5 /usr/bin/chronyc -n tracking]" } puts $channelId "<<>>" diff --git a/addon/addon/timeout b/addon/addon/timeout index 67a8869..cea8ca3 100755 --- a/addon/addon/timeout +++ b/addon/addon/timeout @@ -21,17 +21,20 @@ else signal=SIGTERM # Options - O=$(getopt -- :t:s: "$@") || exit 1 + O=$(getopt -- :s: "$@") || exit 1 eval set -- "${O}" while true; do case "${1}" in - -t) maxtime=${2}; shift 2;; -s) signal=${2}; shift 2;; --) shift; break;; *) exit 1;; esac done + # maxtime has to be the second argument + maxtime=${1} + shift + # lets sleep first sleep "${maxtime}" & SPID=${!}