Differences
This shows you the differences between two versions of the page.
linux_wiki:spacewalk_reboot_check [2016/11/26 23:58] billdozor created |
linux_wiki:spacewalk_reboot_check [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Spacewalk Reboot Check ====== | ||
- | |||
- | **General Information** | ||
- | |||
- | Check running kernel vs newest installed to see if the system needs a reboot. | ||
- | |||
- | **Checklist** | ||
- | * Spacewalk server configured | ||
- | * Spacewalk client registered | ||
- | * System with spacecmd configured | ||
- | |||
- | ---- | ||
- | |||
- | ====== The Script ====== | ||
- | |||
- | Execute on a system that has spacecmd installed and configured. | ||
- | |||
- | <code bash sw_reboot-check.sh> | ||
- | #!/bin/bash | ||
- | # Name: sw_reboot-check.sh | ||
- | # Description: | ||
- | # Last Modified: 2016-10-07 | ||
- | # Recent Changes: | ||
- | # -Minor spelling correction and added comments | ||
- | #################################################################################### | ||
- | |||
- | ##### 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 | ||
- | } | ||
- | |||
- | # | ||
- | # 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 to check all systems | ||
- | all_systems=" | ||
- | |||
- | ## Get command line arguments ## | ||
- | while getopts " | ||
- | case " | ||
- | h) # -h (help) argument | ||
- | show_usage | ||
- | exit 0 | ||
- | ;; | ||
- | s) # -s system | ||
- | single_system=${OPTARG} | ||
- | check_type=" | ||
- | ;; | ||
- | g) # -g system-group | ||
- | system_group=${OPTARG} | ||
- | check_type=" | ||
- | ;; | ||
- | a) # -a (all systems) | ||
- | all_systems=" | ||
- | check_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 | ||
- | # | ||
- | |||
- | # 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 | ||
- | |||
- | # | ||
- | # Main starts here | ||
- | # | ||
- | |||
- | echo -e " | ||
- | echo -e "#### | ||
- | echo -e " | ||
- | echo | ||
- | echo -e "Check the following systems to see if they need a reboot..." | ||
- | if [[ ${single_system} ]]; then | ||
- | echo -e " | ||
- | elif [[ ${system_group} ]]; then | ||
- | echo -e " | ||
- | else | ||
- | echo -e " | ||
- | fi | ||
- | echo -e " | ||
- | read run_script | ||
- | |||
- | if [[ ${run_script} != " | ||
- | echo -e " | ||
- | exit 1 | ||
- | fi | ||
- | |||
- | ### Kernel Variable Intent ### | ||
- | ## kernel_running -> Get reported running kernel and filter output with sed to remove x86_64 | ||
- | # (leaving version number only) | ||
- | ## kernel_latest -> Get installed kernels, filter kernel- and x86_64 from the name | ||
- | # (leaving version number only). Then, sort list (field sep = ' | ||
- | # tail -1 to get the highest version installed | ||
- | |||
- | ## Check System Running and Installed Kernels ## | ||
- | case ${check_type} in | ||
- | single) | ||
- | ## Single system ## | ||
- | echo -e " | ||
- | kernel_running=" | ||
- | kernel_latest=" | ||
- | |||
- | if [[ ${kernel_running} != ${kernel_latest} ]]; then | ||
- | echo -e " | ||
- | fi | ||
- | ;; | ||
- | |||
- | group) | ||
- | ## Group of systems (Spacewalk Group) ## | ||
- | echo -e " | ||
- | |||
- | for node in $(${spacecmd_cmd} group_listsystems ${system_group}); | ||
- | echo -e "-> Checking ${node}..." | ||
- | kernel_running=" | ||
- | kernel_latest=" | ||
- | |||
- | if [[ ${kernel_running} != ${kernel_latest} ]]; then | ||
- | echo -e " | ||
- | fi | ||
- | done | ||
- | ;; | ||
- | |||
- | all) | ||
- | ## All Systems ## | ||
- | echo -e " | ||
- | |||
- | for node in $(${spacecmd_cmd} system_list); | ||
- | echo -e "-> Checking ${node}..." | ||
- | kernel_running=" | ||
- | kernel_latest=" | ||
- | |||
- | if [[ ${kernel_running} != ${kernel_latest} ]]; then | ||
- | echo -e " | ||
- | fi | ||
- | done | ||
- | ;; | ||
- | esac | ||
- | |||
- | echo -e " | ||
- | echo -e "=- Reboot Check Completed. -=" | ||
- | echo -e " | ||
- | </ | ||
- | |||
- | ---- | ||