jeudi 28 octobre 2021

Else part of if/else statement not entered

I have the following bash script, which is used to open or close a relais depending whether certain applications are running or not.

The script basically works, so if all applications are running, the relais is closed. If one of the applications is not running, the else part for the statement should be entered. Unfortunately this doesn't happen, even if one of the applications return status "dead".

core_state=$(systemctl status auxiliocore.service | grep -o -P "(?<=active \().*(?=\))")
corerestapi_state=$(systemctl status auxiliocorerestapi.service | grep -o -P "(?<=active \().*(?=\))")
console_state=$(systemctl status auxilioconsole.service | grep -o -P "(?<=active \().*(?=\))")

echo $core_state
echo $corerestapi_state
echo $console_state

if [[ $core_state -eq "running" && $corerestapi_state -eq "running" && $console_state -eq "running" ]]; then
    echo $(date) "- all applications active."
    echo "1" >> /run/bspd/legacy/relais1
else
    echo $(date) "- at least one application is not running."
    echo "0" >> /run/bspd/legacy/relais1
fi

Aucun commentaire:

Enregistrer un commentaire