From a3541096eee852ead1f0e3ec588c79e8c4846dc9 Mon Sep 17 00:00:00 2001 From: Pavel Muhortov Date: Thu, 4 May 2023 16:48:48 +0300 Subject: [PATCH] add printing number of Zimbra stopped services --- README.md | 1 + zimbra-man.sh | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9e65cef..b8de493 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ ____ |-----------|--------------|------------------------|---------------| | 1 |**[qn]**|execution without pauses|| | 2 |**que**|print length of all zimbra queues|`None`| +| 2 |**svc**|print number of stopped services|`None`| | 2 |**ssl**|letsencrypt certificate update procedure|`None`| | 3 |**[/path/to/conf]**|custom configuration file path|`./zimbra-man.conf`| diff --git a/zimbra-man.sh b/zimbra-man.sh index e0a7e4e..09bf7e7 100644 --- a/zimbra-man.sh +++ b/zimbra-man.sh @@ -17,6 +17,7 @@ # PARAMETERS: # 1: "qn" - execution without pauses # 2: "que" - print length of all zimbra queues +# 2: "svc" - print number of stopped services # 2: "ssl" - letsencrypt certificate update procedure # 3: custom configuration file path # @@ -123,6 +124,28 @@ calcqueue(){ return "${object}" } +####################################### +# Counting zimbra stopped services. +# Globals: +# None +# Arguments: +# None +# return: +# number of stopped services +####################################### +isrunning(){ + counter=0 + while read -r service; do + if ! grep -q "$(cat /etc/hostname)" <<< "${service}"; then + if grep -q "Stopped" <<< "${service}"; then + (( counter++ )) + fi + fi + done <<< "$(su - zimbra -c '/opt/zimbra/bin/zmcontrol status')" + printf "%s\n" "${counter}" + return "${counter}" +} + ####################################### # Print certificate expiration date in epoch # Globals: @@ -236,9 +259,7 @@ fi # if checkroot; then - if [ "${does}" = "que" ]; then - calcqueue && exit 0 - elif [ "${does}" = "ssl" ]; then + if [ "${does}" = "ssl" ]; then expired=$(certcheck "/etc/letsencrypt/live/${certfirst}/cert.pem") targets=$(( expired - 2592000 )) if [[ "${time}" -le "${targets}" ]]; then @@ -248,6 +269,16 @@ if checkroot; then certrenew && addtologs "${certfirst} certificates renewed" startsendmail fi + elif [ "${does}" = "que" ]; then + result=$(calcqueue) + addtologs "Zimbra queue has ${result} objects" > /dev/null + printf "%s\n" "${result}" + execquite > /dev/null + elif [ "${does}" = "svc" ]; then + result=$(isrunning) + addtologs "Zimbra has ${result} stopped services" > /dev/null + printf "%s\n" "${result}" + execquite > /dev/null else printf "%s\n" "Usage example: $0 qn ssl" printf "%s\n" "Usage example: $0 - que"