Introduction
A service health check script helps you quickly see if a service on your computer or server is running well or needs attention.
#!/bin/bash if systemctl is-active --quiet SERVICE_NAME; then echo "SERVICE_NAME is running" else echo "SERVICE_NAME is NOT running" fi
#!/bin/bash if systemctl is-active --quiet apache2; then echo "Apache is running" else echo "Apache is NOT running" fi
#!/bin/bash if systemctl is-active --quiet sshd; then echo "SSH service is running" else echo "SSH service is NOT running" fi
#!/bin/bash SERVICE_NAME="cron" if systemctl is-active --quiet "$SERVICE_NAME"; then echo "$SERVICE_NAME is running" else echo "$SERVICE_NAME is NOT running" fi
service health check script in bash?nginx using systemctl in bash?systemctl status servicename.ssh service is running?if systemctl is-active --quiet ssh; then echo "SSH service is running" else echo "SSH service is stopped" fi
if systemctl status apache2; then echo "Apache2 is running" else echo "Apache2 is stopped" fi
systemctl is-active --quiet to get proper exit code check without any output.nginx, mysql, and redis. Which script snippet correctly loops over these services and prints their status using systemctl is-active --quiet?systemctl is-active --quiet correctly to check service status and prints appropriate message.Pass the test and this pattern moves unknown