From 6142263b8bcd8cd46d87b51bcf7b16134f506023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20M=C3=B6lle?= Date: Wed, 19 Apr 2023 19:28:17 +0200 Subject: [PATCH] =?UTF-8?q?=E2=80=9Erunupdate.sh=E2=80=9C=20hinzuf=C3=BCge?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runupdate.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 runupdate.sh diff --git a/runupdate.sh b/runupdate.sh new file mode 100644 index 0000000..bede099 --- /dev/null +++ b/runupdate.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# List of server IP addresses as strings +SERVER_LIST=("192.168.1.100" "192.168.1.101" "192.168.1.102") + +# Loop through the server list +for SERVER in "${SERVER_LIST[@]}" +do + echo "Checking for updates on server: ${SERVER}" + + # Establish SSH connection to remote server and run commands to check for updates + SSH_RESULT=$(ssh username@${SERVER} "sudo apt-get update > /dev/null && apt list --upgradable") + + # If updates are available, inform the user + if [ -n "${SSH_RESULT}" ]; then + echo "Updates available on server ${SERVER}:" + echo "${SSH_RESULT}" + echo "" + else + echo "No updates available on server ${SERVER}" + echo "" + fi +done + +# Prompt user to confirm if they want to update the listed servers +read -p "Do you want to update the listed servers? (Yes/No): " UPDATE_CONFIRMATION + +# If the user confirms with "Yes", update the servers and store the update status for each server in a list +if [[ $UPDATE_CONFIRMATION == "Yes" ]]; then + UPDATE_STATUS=() + for SERVER in "${SERVER_LIST[@]}" + do + echo "Updating server: ${SERVER}" + + # Establish SSH connection to remote server and run commands to update + ssh username@${SERVER} "sudo apt-get update > /dev/null && sudo apt-get upgrade -y" > /dev/null 2>&1 + + # Check the return value of ssh to determine if the update was successful + if [[ $? -eq 0 ]]; then + UPDATE_STATUS+=("${SERVER}: Update successful") + echo "Server ${SERVER} updated." + else + UPDATE_STATUS+=("${SERVER}: Update failed") + echo "Failed to update server ${SERVER}." + fi + done + + # Summary of update status + echo "" + echo "Summary of update status:" + for STATUS in "${UPDATE_STATUS[@]}" + do + echo "${STATUS}" + done +else + echo "Updates cancelled." +fi