From 34e47ee0e0dca6d0d076d7de261bdc3ff2a9b851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Wed, 25 Jan 2023 10:35:07 +0100 Subject: [PATCH] Cleaner way to get systemd unit state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SeeĀ : https://unix.stackexchange.com/a/396633 --- ur/fortinet.vpn.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ur/fortinet.vpn.sh b/ur/fortinet.vpn.sh index 137e817..f31d1b5 100755 --- a/ur/fortinet.vpn.sh +++ b/ur/fortinet.vpn.sh @@ -213,7 +213,7 @@ main() { # {{{ if [ "${request_status}" = "start" ]; then debug_message "-- Connect VPN BEGIN" ### If forticlient.service unit is not started {{{ - systemd_forticlient_status=$(systemctl show forticlient.service | grep "^ActiveStat" | sed 's/.*=\(.*\)/\1/' || error_message "Error while requesting forticlient.service unit status." 21) + systemd_forticlient_status=$(systemctl show --property ActiveState --value forticlient.service || error_message "Error while requesting forticlient.service unit status." 21) if [ "${systemd_forticlient_status}" = "failed" ]; then debug_message "| Try to start forticlient.service unit." sudo systemctl restart forticlient.service \ @@ -221,7 +221,7 @@ main() { # {{{ fi ### }}} ### If forticlient.service unit is started {{{ - systemd_forticlient_status=$(systemctl show forticlient.service | grep "^ActiveStat" | sed 's/.*=\(.*\)/\1/' || error_message "Error while requesting forticlient.service unit status." 21) + systemd_forticlient_status=$(systemctl show --property ActiveState --value forticlient.service || error_message "Error while requesting forticlient.service unit status." 21) if [ "${systemd_forticlient_status}" = "active" ]; then debug_message "| forticlient.service unit is ${RED}started${COLOR_DEBUG}." fi