Differences
This shows you the differences between two versions of the page.
— |
linux_wiki:freeipa_report_host_groups_empty [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== FreeIPA Report Host Groups Empty ====== | ||
+ | |||
+ | **General Information** | ||
+ | |||
+ | Report Host Groups that don't have any members. | ||
+ | |||
+ | **Checklist** | ||
+ | * Distro(s): Enterprise Linux 6/7 | ||
+ | * Other: [[http:// | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== The Script ====== | ||
+ | |||
+ | <code bash report-hostgroups-empty.sh> | ||
+ | #!/bin/bash | ||
+ | # Name: report-hostgroups-empty.sh | ||
+ | # Description: | ||
+ | # Last Modified: 2018-05-31 | ||
+ | # Recent Changes: | ||
+ | ############################################################################################### | ||
+ | |||
+ | ##### Customize These Variables ##### | ||
+ | # IPA admin user | ||
+ | admin_user=" | ||
+ | ##### End of Customize Variables ##### | ||
+ | |||
+ | # | ||
+ | # Functions; Main starts after | ||
+ | # | ||
+ | function show_usage | ||
+ | { | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e "-> FreeIPA admin access." | ||
+ | echo -e | ||
+ | } | ||
+ | |||
+ | # | ||
+ | # Get Script Arguments | ||
+ | # | ||
+ | # Reset POSIX variable in case it has been used previously in this shell | ||
+ | OPTIND=1 | ||
+ | |||
+ | # By default, do not output verbose | ||
+ | verbose_mode=" | ||
+ | |||
+ | while getopts " | ||
+ | case " | ||
+ | h) # -h (help) argument | ||
+ | show_usage | ||
+ | exit 0 | ||
+ | ;; | ||
+ | v) # -v (verbose) argument | ||
+ | verbose_mode=" | ||
+ | ;; | ||
+ | *) # invalid argument | ||
+ | show_usage | ||
+ | exit 0 | ||
+ | ;; | ||
+ | esac | ||
+ | done | ||
+ | |||
+ | # | ||
+ | # Pre-checks: Make sure we have good options set | ||
+ | # | ||
+ | # See if we have a kerberos ticket, if not, prompt login | ||
+ | / | ||
+ | if [[ $? -ne 0 ]]; then | ||
+ | echo ">> | ||
+ | / | ||
+ | echo | ||
+ | fi | ||
+ | |||
+ | # | ||
+ | # Main starts here | ||
+ | # | ||
+ | echo -e " | ||
+ | echo -e "#### | ||
+ | echo -e " | ||
+ | echo | ||
+ | echo -e "This script will report all host groups that don't have any members." | ||
+ | if [[ ${verbose_mode} == " | ||
+ | echo -e " | ||
+ | else | ||
+ | echo -e " | ||
+ | fi | ||
+ | echo -e " | ||
+ | read run_script | ||
+ | |||
+ | if [[ ${run_script} != " | ||
+ | echo -e " | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | # Get all host groups | ||
+ | echo -e ">> | ||
+ | all_hostgroups=" | ||
+ | |||
+ | # Initialize lists to nothing | ||
+ | hostgroup_nomembers="" | ||
+ | hostgroup_error="" | ||
+ | |||
+ | echo -e ">> | ||
+ | if [[ ${verbose_mode} == " | ||
+ | # Extra newline required if verbose messages (due to \c above) | ||
+ | echo | ||
+ | fi | ||
+ | |||
+ | # Loop through all hostgroups, add ones with no members to the list | ||
+ | for hostgroup in ${all_hostgroups}; | ||
+ | |||
+ | if [[ ${verbose_mode} == " | ||
+ | echo " | ||
+ | else | ||
+ | # Not verbose, output a single ' | ||
+ | echo -e " | ||
+ | fi | ||
+ | |||
+ | ipa hostgroup-show ${hostgroup} | grep ' | ||
+ | return_code=" | ||
+ | |||
+ | if [[ ${return_code} == " | ||
+ | # Members found | ||
+ | if [[ ${verbose_mode} == " | ||
+ | echo " | ||
+ | else | ||
+ | # Do nothing ':' | ||
+ | : | ||
+ | fi | ||
+ | |||
+ | elif [[ ${return_code} == " | ||
+ | # No members found | ||
+ | if [[ ${verbose_mode} == " | ||
+ | echo "---No members. (${hostgroup})" | ||
+ | fi | ||
+ | hostgroup_nomembers+=" | ||
+ | |||
+ | else | ||
+ | # Some other error occurred | ||
+ | if [[ ${verbose_mode} == " | ||
+ | echo " | ||
+ | fi | ||
+ | hostgroup_error+=" | ||
+ | fi | ||
+ | done | ||
+ | |||
+ | if [[ ${verbose_mode} == " | ||
+ | # Extra space required if not verbose because of no newlines for ' | ||
+ | echo -e " | ||
+ | fi | ||
+ | |||
+ | echo -e " | ||
+ | echo -e "---- Host Groups with No Members ----" | ||
+ | echo -e " | ||
+ | |||
+ | echo -e " | ||
+ | for hostgroup in ${hostgroup_nomembers}; | ||
+ | echo -e " | ||
+ | done | ||
+ | |||
+ | echo -e " | ||
+ | for hostgroup in ${hostgroup_error}; | ||
+ | echo -e " | ||
+ | done | ||
+ | |||
+ | echo -e " | ||
+ | echo -e "=- Report: Empty Host Groups Completed. -=" | ||
+ | echo -e " | ||
+ | </ | ||
+ | |||
+ | ---- | ||