51 lines
1.1 KiB
Bash
51 lines
1.1 KiB
Bash
#!/bin/bash
|
|
|
|
# List of servers to update
|
|
servers=(10.0.0.50 10.0.0.51)
|
|
|
|
# SSH username for remote access
|
|
user=root
|
|
|
|
# Function to check for updates on a remote server
|
|
check_updates () {
|
|
ssh $user@$1 "sudo apt-get update > /dev/null && apt list --upgradable"
|
|
}
|
|
|
|
# Function to update a remote server
|
|
update_server () {
|
|
ssh $user@$1 "sudo apt-get update > /dev/null && sudo apt-get upgrade -y" > /dev/null 2>&1
|
|
if [ $? -eq 0 ]; then
|
|
echo "Update successful on $1"
|
|
else
|
|
echo "Update failed on $1"
|
|
fi
|
|
}
|
|
|
|
# Loop through servers and check for updates
|
|
for server in "${servers[@]}"
|
|
do
|
|
echo "Checking for updates on $server"
|
|
updates=$(check_updates $server)
|
|
if [ -n "$updates" ]; then
|
|
echo "Updates available on $server:"
|
|
echo "$updates"
|
|
else
|
|
echo "No updates available on $server"
|
|
fi
|
|
done
|
|
|
|
# Prompt user to confirm update
|
|
read -p "Do you want to update these servers? (y/n): " response
|
|
if [ "$response" != "y" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
# Loop through servers and update
|
|
for server in "${servers[@]}"
|
|
do
|
|
echo "Updating $server"
|
|
update_server $server
|
|
done
|
|
|
|
echo "Updates completed"
|