Created
March 19, 2025 15:25
-
-
Save MightyBlow/d96a90db6e7faded7c3dbbb9f3169d1c to your computer and use it in GitHub Desktop.
check_status_services.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Цвета | |
GREEN='\033[0;32m' | |
RED='\033[0;31m' | |
NC='\033[0m' # No Color | |
services=("nginx" "httpd" "sshd" "docker") | |
for service in "${services[@]}"; do | |
if systemctl show "$service" &>/dev/null; then | |
state=$(systemctl show -p ActiveState "$service" | cut -d= -f2) | |
if [[ "$state" == "active" ]]; then | |
echo -e "$service - состояние: ${GREEN}$state${NC}" | |
else | |
echo -e "$service - состояние: ${RED}$state${NC}" | |
fi | |
else | |
echo -e "$service - сервис не существует" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment