2023-04-19 19:28:17 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-04-19 19:55:00 +02:00
|
|
|
# Read the server list from a file
|
|
|
|
servers_file="servers.conf"
|
|
|
|
if [ ! -f "$servers_file" ]; then
|
|
|
|
echo "Error: $servers_file does not exist."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
servers=($(cat "$servers_file"))
|
2023-04-19 19:51:55 +02:00
|
|
|
|
|
|
|
# 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"
|
2023-04-19 19:57:16 +02:00
|
|
|
elif [ -n "$updates" ]; then
|
2023-04-19 19:51:55 +02:00
|
|
|
echo "Update failed on $1"
|
|
|
|
fi
|
|
|
|
}
|
2023-04-19 19:28:17 +02:00
|
|
|
|
2023-04-19 19:51:55 +02:00
|
|
|
# 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"
|
2023-04-19 19:28:17 +02:00
|
|
|
else
|
2023-04-19 19:51:55 +02:00
|
|
|
echo "No updates available on $server"
|
2023-04-19 19:28:17 +02:00
|
|
|
fi
|
2023-04-19 19:51:55 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
# Prompt user to confirm update
|
|
|
|
read -p "Do you want to update these servers? (y/n): " response
|
|
|
|
if [ "$response" != "y" ]; then
|
|
|
|
exit 0
|
2023-04-19 19:28:17 +02:00
|
|
|
fi
|
2023-04-19 19:51:55 +02:00
|
|
|
|
|
|
|
# Loop through servers and update
|
|
|
|
for server in "${servers[@]}"
|
|
|
|
do
|
|
|
|
echo "Updating $server"
|
|
|
|
update_server $server
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Updates completed"
|