Introduction:
This script checks the status of a given service and informs if it is active or inactive, ensuring your critical services are running.
Code Snippet:
Instructions:
Use the script by making it executable and checking a service status:
Example Output:
This script checks the status of a given service and informs if it is active or inactive, ensuring your critical services are running.
Code Snippet:
Bash:
#!/bin/bash
# Service Status Checker
if [ -z "$1" ]; then
echo "Usage: $0 <service_name>"
exit 1
fi
SERVICE=$1
systemctl is-active --quiet $SERVICE
if [ $? -eq 0 ]; then
echo "$SERVICE is running."
else
echo "$SERVICE is not running."
fi
Instructions:
Use the script by making it executable and checking a service status:
Code:
chmod +x service_status.sh
./service_status.sh apache2
Example Output:
Code:
apache2 is running.