Check if system block is active in bash script

I am writing a script to automatically install the binding server in a CentOs 7 distribution.

I am stuck with systemctl status because it does not generate an error code (this is correct since the state is not an error). I can use.

I want to check if the service is running (active). What is the best and most effective way to do this?

+6
source share
1 answer

The best way to check if a service systemctl is-active command:

 # systemctl start sshd # systemctl is-active sshd >/dev/null 2>&1 && echo YES || echo NO YES # systemctl stop sshd # systemctl is-active sshd >/dev/null 2>&1 && echo YES || echo NO NO 
+26
source

Source: https://habr.com/ru/post/986577/


All Articles