Skip to content

Commit

Permalink
sap_facts.sh - ps print only executable with path
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jhohwieler committed Aug 20, 2024
1 parent e247f47 commit 46d9216
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/modules/sap_facts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 command | grep $2 | grep $3 | grep sapstartsrv | wc -l)

if [[ $SAPSTARTSRV = 0 ]]; then
## No sapstartsrv process running - attempt to start
Expand Down

0 comments on commit 46d9216

Please sign in to comment.