Differences
This shows you the differences between two versions of the page.
— |
linux_wiki:spacewalk_force_client_check_in [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Spacewalk Force Client Check In ====== | ||
+ | |||
+ | **General Information** | ||
+ | |||
+ | Force Spacewalk client(s) to check in and pick up scheduled jobs. | ||
+ | |||
+ | **Checklist** | ||
+ | * Spacewalk server configured | ||
+ | * Spacewalk client registered | ||
+ | * System with spacecmd configured | ||
+ | * Execute as user with sudo privileges on target client systems | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== The Script ====== | ||
+ | |||
+ | Execute on a system that has spacecmd installed and configured. | ||
+ | |||
+ | <code bash sw_force-client-checkin.sh> | ||
+ | #!/bin/bash | ||
+ | # Name: sw_force-client-checkin.sh | ||
+ | # Description: | ||
+ | # Last Updated: 2016-10-07 | ||
+ | # Recent Changes: | ||
+ | # check for single system commands | ||
+ | # -ssh connect timeout 5 seconds added | ||
+ | #################################################################################### | ||
+ | |||
+ | ##### Customize These Variables ##### | ||
+ | # Spacecmd command and any default arguments | ||
+ | spacecmd_cmd=" | ||
+ | |||
+ | ##### End of Customize Variables ##### | ||
+ | |||
+ | # | ||
+ | # Functions; Main starts after | ||
+ | # | ||
+ | function show_usage | ||
+ | { | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e "-s system | ||
+ | echo -e "-g system-group | ||
+ | echo -e " | ||
+ | echo -e " | ||
+ | echo -e "-> Spacecmd and config file setup required." | ||
+ | echo -e "-> Run as a user with admin privileges on the Spacewalk server." | ||
+ | echo -e "-> Run as a user with sudo privileges on the target server(s) for rhn_check." | ||
+ | echo -e | ||
+ | } | ||
+ | |||
+ | # | ||
+ | # Get Script Arguments | ||
+ | # | ||
+ | # Reset POSIX variable in case it has been used previously in this shell | ||
+ | OPTIND=1 | ||
+ | |||
+ | ## Default settings ## | ||
+ | # Do not assume we want all systems to check in | ||
+ | all_systems=" | ||
+ | |||
+ | ## Get command line arguments ## | ||
+ | while getopts " | ||
+ | case " | ||
+ | h) # -h (help) argument | ||
+ | show_usage | ||
+ | exit 0 | ||
+ | ;; | ||
+ | s) # -s system | ||
+ | single_system=${OPTARG} | ||
+ | checkin_type=" | ||
+ | ;; | ||
+ | g) # -g system-group | ||
+ | system_group=${OPTARG} | ||
+ | checkin_type=" | ||
+ | ;; | ||
+ | a) # -a (all systems) | ||
+ | all_systems=" | ||
+ | checkin_type=" | ||
+ | ;; | ||
+ | *) # invalid argument | ||
+ | show_usage | ||
+ | exit 0 | ||
+ | ;; | ||
+ | esac | ||
+ | done | ||
+ | |||
+ | ## Argument Sanity Checks ## | ||
+ | # Scenario: No arguments set | ||
+ | if [[ ${all_systems} == " | ||
+ | if [[ -z ${single_system} && -z ${system_group} ]]; then | ||
+ | echo -e " | ||
+ | show_usage | ||
+ | exit 1 | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | # Scenario: All systems AND single system set | ||
+ | if [[ ${all_systems} == " | ||
+ | echo -e " | ||
+ | show_usage | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | # Scenario: All systems AND system group set | ||
+ | if [[ ${all_systems} == " | ||
+ | echo -e " | ||
+ | show_usage | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | # Scenario: Single system AND system group set | ||
+ | if [[ ${single_system} && ${system_group} ]]; then | ||
+ | echo -e " | ||
+ | show_usage | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | # | ||
+ | # Pre-checks: Ensure dependencies exist | ||
+ | # | ||
+ | |||
+ | # Only check for Spacewalk dependencies if NOT sending to a single system | ||
+ | if [[ -z ${single_system} ]]; then | ||
+ | # Check for Spacecmd | ||
+ | which spacecmd &> /dev/null | ||
+ | if [[ $? -ne 0 ]]; then | ||
+ | echo " | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | # Check to see if a spacecmd config file exists | ||
+ | if [[ ! -f ${HOME}/ | ||
+ | echo -e " | ||
+ | exit 1 | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | # | ||
+ | # Main starts here | ||
+ | # | ||
+ | |||
+ | echo -e " | ||
+ | echo -e "#### | ||
+ | echo -e " | ||
+ | echo | ||
+ | echo -e "Force clients registered to Spacewalk to check in (rhn_check)." | ||
+ | if [[ ${single_system} ]]; then | ||
+ | echo -e "Force single client to check in: ${single_system}" | ||
+ | elif [[ ${system_group} ]]; then | ||
+ | echo -e "Force clients in group to check in: ${system_group}" | ||
+ | else | ||
+ | echo -e "Force ALL systems to check in." | ||
+ | fi | ||
+ | echo -e " | ||
+ | read run_script | ||
+ | |||
+ | if [[ ${run_script} != " | ||
+ | echo -e " | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | case ${checkin_type} in | ||
+ | single) | ||
+ | ## Single system ## | ||
+ | echo -e " | ||
+ | |||
+ | echo " | ||
+ | ssh -qt -o ConnectTimeout=5 ${single_system} "sudo / | ||
+ | |||
+ | ;; | ||
+ | group) | ||
+ | ## Group of systems (Spacewalk Group) ## | ||
+ | echo -e " | ||
+ | |||
+ | # Check to see if the Spacewalk group exists; exit if it does not | ||
+ | ${spacecmd_cmd} group_list | grep ${system_group} > /dev/null | ||
+ | if [[ $? -ne 0 ]]; then | ||
+ | echo -e "-> ERROR! Could not find Spacewalk group: ${system_group}" | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | for node in $(${spacecmd_cmd} group_listsystems ${system_group}); | ||
+ | echo " | ||
+ | ssh -qt -o ConnectTimeout=5 ${node} "sudo / | ||
+ | done | ||
+ | |||
+ | ;; | ||
+ | all) | ||
+ | ## All Systems ## | ||
+ | echo -e " | ||
+ | |||
+ | for node in $(${spacecmd_cmd} system_list); | ||
+ | echo " | ||
+ | ssh -qt -o ConnectTimeout=5 ${node} "sudo / | ||
+ | done | ||
+ | |||
+ | ;; | ||
+ | esac | ||
+ | |||
+ | echo -e " | ||
+ | echo -e "=- Client Check In(s) Completed. -=" | ||
+ | echo -e " | ||
+ | </ | ||
+ | |||
+ | ---- | ||