From 50444af89762070b9255378ad2abe2e96cb61096 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Fri, 20 May 2022 09:51:16 +0200 Subject: [PATCH] update _wait_4_free_slot and data in debug.log --- cm.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cm.sh b/cm.sh index ea8d00c..54ffc68 100755 --- a/cm.sh +++ b/cm.sh @@ -33,6 +33,7 @@ # 2022-04-20 <axel.hahn@iml.unibe.ch> fix multiple domains using domain alias # 2022-04-21 <axel.hahn@iml.unibe.ch> mix multiple domains using domain alias or not # 2022-05-19 <axel.hahn@iml.unibe.ch> add timer and debug.log +# 2022-05-20 <axel.hahn@iml.unibe.ch> update _wait_4_free_slot and data in debug.log # ====================================================================== @@ -327,13 +328,7 @@ function _testUser(){ # param string(s) message function _debuglog(){ if [ ${CM_writedebuglog} -eq 1 ]; then - local _sProcesses - typeset -i local _iProcesses - typeset -i local _iPos - _sProcesses=$( ps -ef | grep "bash.*$0" | grep -v "ssh.*@" | grep -v "grep" | sort -k 2 -n ) - _iProcesses=$( echo "$_sProcesses" | wc -l ) - _iPos=$( echo "$_sProcesses" | grep -n " $$ " | head -1 | cut -f 1 -d ':' ) - echo "$( date ) $CM_fqdn [$$] | $(show_timer) | pos $_iPos of $_iProcesses processes | $*" >> ${debuglogfile} + echo "$( date ) $CM_fqdn [$$] | $(show_timer) | $*" >> ${debuglogfile} fi } @@ -351,23 +346,28 @@ function _wait_for_free_slot(){ local _bWait=true _debuglog "start in _wait_for_free_slot" typeset -i local _iFirstPID=0 + typeset -i local _iPos=0 local _sProcesses + sleep 3 _wd "--- Need to wait until own process PID $$ is on top ... " while [ $_bWait = true ]; do _sProcesses=$( ps -ef | grep "bash.*$0" | grep -v "ssh.*@" | grep -v "grep" | sort -k 2 -n ) - # _iFirstPID=$( ps -ef | grep "bash.*$0" | grep -v "ssh.*@" | grep -v "grep" | sort -k 2 -n | head -1 | awk '{ print $2}' ) - _iFirstPID=$( echo "$_sProcesses" | head -1 | awk '{ print $2}' ) + _iPos=$( echo "$_sProcesses" | grep -n " $$ " | head -1 | cut -f 1 -d ':' ) + + _wd "instances: $_iProcesses" + test ${CM_showdebug} -ne 0 && echo "$_sProcesses" - if [ $_iFirstPID -eq $$ ]; then + # if [ $_iFirstPID -eq $$ ]; then + if [ $_iPos -eq 1 ]; then _bWait=false + _debuglog "GO from _wait_for_free_slot" _wd "OK. Go!" else - _wd "- all instances" - _debuglog "waiting in _wait_for_free_slot" - # test ${CM_showdebug} && ps -ef | grep "bash.*$0" | grep -v "ssh.*@" | grep -v "grep" | sort -k 2 -n - test ${CM_showdebug} -ne 0 && echo "$_sProcesses" + _iProcesses=$( echo "$_sProcesses" | wc -l ) + _iFirstPID=$( echo "$_sProcesses" | head -1 | awk '{ print $2}' ) + _debuglog "zzz ... waiting in _wait_for_free_slot ... $_iFirstPID is first ... my pos is $_iPos of $_iProcesses" sleep 10 fi done -- GitLab