diff --git a/check-reboot b/check-reboot new file mode 100755 index 0000000..7aad58c --- /dev/null +++ b/check-reboot @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -euo pipefail + +HOSTS_FILE="${HOME}/.server_hosts" +host_array=() +YELLOW='\033[1;33m' +GREEN='\033[1;32m' +NC='\033[0m' + +# Read hosts from ~/.server_hosts +while IFS= read -r line; do + host_array+=("$line") +done < "${HOSTS_FILE}" + +for host in "${host_array[@]}"; do + hostname=$(echo "$host" | cut --delimiter="@" --fields=2) + if ssh "$host" -- test -f /etc/redhat-release; then + if ssh "$host" -- sudo needs-restarting -r >/dev/null; then + echo -e "$hostname: ${GREEN}OK${NC}" + else + ssh "$host" -- sudo systemctl reboot >/dev/null + echo -e "$hostname: ${YELLOW}Reboot initiated${NC}" + notify-send "$hostname: Reboot initiated" + fi + elif ssh "$host" -- test -f /etc/debian_version; then + if ssh "$host" -- ! test -f /var/run/reboot-required; then + echo -e "$hostname: ${GREEN}OK${NC}" + else + ssh "$host" -- sudo systemctl reboot >/dev/null + echo -e "$hostname: ${YELLOW}Reboot initiated${NC}" + notify-send "$hostname: Reboot initiated" + fi + else + echo "$hostname is not a Debian/Ubuntu or RHEL-compatible system." + echo "Reboot check aborted" + fi +done diff --git a/reboot_check b/reboot_check deleted file mode 100755 index b67e0ab..0000000 --- a/reboot_check +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash - -# This script reads user@host lines from ~/.server_hosts. Each host -# is a RHEL-like operating system where the dnf-utils and -# dnf-automatic packages are installed. dnf-automatic is configured -# to download and apply updates periodically. The 'needs-restarting' -# command provided by the dnf-utils packages is assumed to be -# available on each host. Each host is checked via SSH to see if it -# needs-restarting after core libraries and services have been -# updated since the last boot-up. If a restart has been initiated for -# a given host, notify-send will notify the user. - -set -euo pipefail - -HOST_FILE="${HOME}/.server_hosts" -host_array=() -RED='\033[1;31m' -YELLOW='\033[1;33m' -GREEN='\033[1;32m' -NC='\033[0m' - -# Read hosts from ~/.server_hosts -while IFS= read -r line; do - host=$(echo $line) - host_array+=($host) -done < "${HOST_FILE}" - -for host in "${host_array[@]}"; do - hostname=$(echo $host | cut --delimiter="@" --fields=2) - if ssh "$host" -- sudo needs-restarting -r >/dev/null; then - echo -e "$hostname: ${GREEN}OK${NC}" - else - ssh "$host" -- sudo systemctl reboot >/dev/null - echo -e "$hostname: ${RED}Restart initiated${NC}" - notify-send "$hostname: Restart initiated" - fi -done