From 8ee89932d821d57b4d7a6ac0150ef1aaff503103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwieler?= <108819130+jhohwieler@users.noreply.github.com> Date: Mon, 19 Aug 2024 09:47:30 +0200 Subject: [PATCH] sap_facts.sh - ps print only executable with path The output of "ps -ef" not also includes the command but also the process age and process arguments. Both can have digits in its string which may interfere when grepping for an instance number like 00 or 01. To fix this, let ps print only the executable with its path. Example: ps with default output - 2 lines match where only 1st line should match /usr/sap/A22/D01/exe/sapstartsrv pf=/usr/sap/A22/SYS/profile/A22_D01_sapa22u01 -D -u a22adm /usr/sap/A22/ASCS02/exe/sapstartsrv pf=/usr/sap/A22/SYS/profile/A22_ASCS02_sapa22u01 -D -u a22adm Example: ps with custom layout, only one line matches as expected /usr/sap/A22/D01/exe/sapstartsrv --- plugins/modules/sap_facts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/sap_facts.sh b/plugins/modules/sap_facts.sh index 8706585..389e345 100755 --- a/plugins/modules/sap_facts.sh +++ b/plugins/modules/sap_facts.sh @@ -286,7 +286,7 @@ function check_sapstartsrv(){ # $3 - NR ## Count the number of sapstartsrv processes - SAPSTARTSRV=$(ps -ef | grep $2 | grep $3 | grep sapstartsrv | wc -l) + SAPSTARTSRV=$(ps -eo exe | grep $2 | grep $3 | grep sapstartsrv | wc -l) if [[ $SAPSTARTSRV = 0 ]]; then ## No sapstartsrv process running - attempt to start