From 0141ec027b6427165850ad064cae466190132bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Wed, 24 Jun 2020 11:51:24 +0200 Subject: [PATCH] Exit if any proc related to maco runs --- cluster/maco.remove.jobs.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cluster/maco.remove.jobs.sh b/cluster/maco.remove.jobs.sh index c3ad302..3823c60 100755 --- a/cluster/maco.remove.jobs.sh +++ b/cluster/maco.remove.jobs.sh @@ -42,6 +42,29 @@ debug_message() { # {{{ ## Print message if DEBUG is enable (=0) [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME}: ${local_message}" +} +# }}} +is_proc_running() { # {{{ + + local_proc_pattern="${1}" + + local_count_proc_pattern="$(pgrep -f -- "${local_proc_pattern}" | wc -l)" + + case "${local_count_proc_pattern}" in + 0 ) ## No procs related to this pattern are running + return_proc_running="1" + ;; + * ) ## At least one proc seems running + return_proc_running="0" + ;; +esac + + ## Simple debug message to valid current variables + debug_message "is_proc_running − \ +procs running (with the pattern: ${RED}${local_proc_pattern}${COLOR_DEBUG}) on the current host: ${RED}${local_count_proc_pattern}${COLOR_DEBUG}." + + return "${return_proc_running}" + } # }}} remove_cron() { # {{{ @@ -59,6 +82,13 @@ Try to remove cron jobs (autoupdate, benchmark,…)." # }}} main() { # {{{ + maco_proc_pattern="(/opt/maco/bin/maco.autoupdate.sh)" + + ## If anything related to maco is currently running + ### Exit + is_proc_running "${maco_proc_pattern}" \ + && exit 0 + remove_cron }