Skip to content

Instantly share code, notes, and snippets.

@arsalanyavari
Created June 20, 2025 00:31
Show Gist options
  • Select an option

  • Save arsalanyavari/a3089e5784d3d6a1726a2518168cceb7 to your computer and use it in GitHub Desktop.

Select an option

Save arsalanyavari/a3089e5784d3d6a1726a2518168cceb7 to your computer and use it in GitHub Desktop.
This gist is only for educational content based on a course and has no other use.
#!/usr/bin/env bash
active_services_cnt=0
total_services_cnt=0
check_service_is_active() {
service_name=$1
systemctl is-active $service_name
}
SERVICES_NAME_LIST=$(systemctl --type=service --all --no-pager --no-legend --plain | awk '{print $1}')
for service_name in $SERVICES_NAME_LIST; do
is_active=$(check_service_is_active $service_name)
if [[ $is_active == "active" ]]; then
((active_services_cnt++))
fi
((total_services_cnt++))
done
active_services_percentage=$((100*active_services_cnt/total_services_cnt))
echo "The percnetage of active services is: $active_services_percentage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment