[packages/rpm-pld-macros] Read the command block in %nagios_nrpe with awk, not a sed range

arekm arekm at pld-linux.org
Sun Sep 6 13:22:33 CEST 2026


commit 1b8235949f63f500127139cbae66e210518d9973
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Sun Sep 6 13:15:48 2026 +0200

    Read the command block in %nagios_nrpe with awk, not a sed range
    
    A range opened at command_name loses a block that lists command_line
    first, and the name acts as a regex, check.foo matching checkXfoo too.

 macros.nagios | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/macros.nagios b/macros.nagios
index 1a9db5b..df8275b 100644
--- a/macros.nagios
+++ b/macros.nagios
@@ -17,6 +17,7 @@
 # %nagios_nrpe -d %{plugin} -f %{_sysconfdir}/%{plugin}.cfg
 #
 # Requirements:
+# Requires:			awk
 # Requires:			grep
 # Requires:			sed >= 4.0
 # BuildRequires:	rpmbuild(macros) >= 1.685
@@ -30,7 +31,11 @@
 	%{-a:# on -a and config exists \
 	if [ -f /etc/nagios/nrpe.cfg ]; then \
 		if [ ! -f $file ] || ! %{__grep} -q '^command\[%{-a*}\]' $file; then \
-			%{__sed} -ne '/^[ \t]*command_name[ \t]\+%{-a*}[ \t]*$/,/\}/{s/^[ \t]*command_line[ \t]\+\(.\+\)/command[%{-a*}]=\1/p}' %{-f*} >> $file; \
+			%{__awk} -v n='%{-a*}' ' \
+				/^[ \t]*command_name[ \t]/ { v = $0; sub(/^[ \t]*command_name[ \t]+/, "", v); sub(/[ \t]+$/, "", v); hit = (v == n) } \
+				/^[ \t]*command_line[ \t]/ { line = $0; sub(/^[ \t]*command_line[ \t]+/, "", line) } \
+				/^[ \t]*\}/ { if (hit && line != "") print "command[" n "]=" line; hit = 0; line = "" } \
+			' %{-f*} >> $file; \
 		fi; \
 	fi;} \
 	%{-d:# on package remove, -d and config exists \
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/rpm-pld-macros.git/commitdiff/5045c35fa3fcc8042179d2213807a61837588e58



More information about the pld-cvs-commit mailing list