#!/bin/bash # Function to run SSH command and handle errors run_ssh() { server=$1 command=$2 echo "===== $server =====" ssh -T $server "$command" & # Capture the PID of the last background process pid=$! # Wait for the background process to finish wait $pid # Check the exit status of the background process if [ $? -eq 0 ]; then echo "Successfully upgraded $server." else echo "Failed to upgrade $server. Check the connection and try again." fi } # Run SSH commands for each server run_ssh "oc" 'sudo apt-get upgrade -y' run_ssh "tk" 'sudo apt-get upgrade -y' run_ssh "rpi3" 'sudo apt-get upgrade -y' run_ssh "cse-z" 'sudo apt-get upgrade -y' run_ssh "hp" 'sudo apt-get upgrade -y' run_ssh "od-xu4" 'yay' echo "Upgrade process completed for all servers."