Skip to content

Instantly share code, notes, and snippets.

@MightyBlow
Created March 19, 2025 15:25
Show Gist options
  • Save MightyBlow/d96a90db6e7faded7c3dbbb9f3169d1c to your computer and use it in GitHub Desktop.
Save MightyBlow/d96a90db6e7faded7c3dbbb9f3169d1c to your computer and use it in GitHub Desktop.
check_status_services.sh
#!/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