Bladeren bron

Refined process-detection by using pgrep, making it more clear

Michael Honkoop 1 week geleden
bovenliggende
commit
6a6493b533
1 gewijzigde bestanden met toevoegingen van 9 en 7 verwijderingen
  1. 9 7
      localchecks/groupwise.sh

+ 9 - 7
localchecks/groupwise.sh

@@ -8,9 +8,11 @@
 # - Initial release of the script
 # v1.1:
 # - Aligned quotation marks around variables cosistently
-
+# v1.2:
+# - started refining the script to a more modern bash-style
+#
 # Current active version of the script
-SCRIPT_VERSION=1.1
+SCRIPT_VERSION=1.2
 
 ################################################################
 # Global definitions for the script - change to fit your needs #
@@ -38,8 +40,8 @@ then
     then
         echo "DEBUG: gwMTA is enabled in config, checking for the process."
     fi
-    gwMTAProcess=$(ps -ef | grep "gwmta" | grep -v grep | awk '{print $2}')
-    if [ ! -z "$gwMTAProcess" ]
+    gwMTAProcess=$(pgrep -x gwmta)
+    if [[ -n "$gwMTAProcess" ]]
     then
         if [ "$debug" -eq 1 ]
         then
@@ -77,7 +79,7 @@ then
     then
         echo "DEBUG: gwPOA is enabled in config, checking for the process."
     fi
-    gwPOAProcess=$(ps -ef | grep "gwpoa" | grep -v grep | awk '{print $2}')
+    gwPOAProcess=$(pgrep -x gwpoa)
     if [ ! -z "$gwPOAProcess" ]
     then
         if [ "$debug" -eq 1 ]
@@ -114,7 +116,7 @@ then
     then
         echo "DEBUG: gwIA is enabled in config, checking for the process."
     fi
-    gwIAProcess=$(ps -ef | grep "gwia" | grep -v grep | awk '{print $2}')
+    gwIAProcess=$(pgrep -x gwia)
     if [ ! -z "$gwIAProcess" ]
     then
         gwIAListener=$(ss -lpn | grep "$gwIAProcess" |awk '{print $5}' | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort -u | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')
@@ -141,7 +143,7 @@ then
     fi
 fi
 
-gwAdminProcess=$(ps -ef | grep gwadmin.jar | grep -v grep | awk '{print $2}')
+gwAdminProcess=$(pgrep -f 'gwadmin\.jar')
 if [ ! -z "$gwAdminProcess" ]
 then
     if [ "$debug" -eq 1 ]