Skip to content

Bash script for automated updates of xenServer

Without a license, xenCenter will tell you what updates are needed and point you to the webpages to download them.

If you download them all manually to a folder, you can use the below script to deploy them. It works on linux only (not osx). Some of the updates may fail if you don’t put your host in maintenance mode.

#!/bin/bash

#This script takes two arguements, the source folder of all the updates and the xenserver you want to patch
#e.g. xen_updater.sh ~/Downloads/xen_updates 172.20.10.74

if [ $# -eq 2 ]; then

source_directory=$1
destination_directory=/var/tmp/`date -I`
destination_host=$2

#first we unzip the files
for i in `ls $source_directory/*.zip`; do unzip -n -d $source_directory $i; done

#then we copy the files to the xenserver
echo "Files will be copied to $destination_host in the directory $destination_directory"
ssh root@$destination_host "mkdir -p $destination_directory"
scp $source_directory/*.xsupdate root@$destination_host:$destination_directory/

#time to apply the patches
patches=$(ssh root@$destination_host "ls $destination_directory/*.xsupdate")
echo "patches to be applied:"
echo "$patches"

for i in $patches; do
        uuid=$(ssh root@${destination_host} "/opt/xensource/bin/xe patch-upload file-name=${i} 2>&1 | grep uuid")
#       echo "$uuid"
        uuid_fixed=$(echo $uuid | awk '{print $2}')
#       echo "$uuid_fixed"
        echo "installing: $i uuid:$uuid_fixed"
        ssh root@$destination_host "/opt/xensource/bin/xe patch-pool-apply uuid=${uuid_fixed} 2>&1"
        echo "removing: $i to save space"
        ssh root@$destination_host "rm $i"
        done

else
        echo "This script takes two arguements, the source folder of all the updates and the xenserver you want to patch \n e.g. xen_updater.sh ~/Downloads/xen_updates 172.20.10.74"
fi

Post a Comment

You must be logged in to post a comment.