{"id":330,"date":"2014-01-23T20:33:55","date_gmt":"2014-01-24T03:33:55","guid":{"rendered":"http:\/\/infinitedisorder.com\/?p=330"},"modified":"2015-12-01T16:31:31","modified_gmt":"2015-12-01T23:31:31","slug":"bash-script-for-automated-updates-of-xenserver","status":"publish","type":"post","link":"https:\/\/infinitedisorder.com\/?p=330","title":{"rendered":"Bash script for automated updates of xenServer"},"content":{"rendered":"<p>Without a license, xenCenter will tell you what updates are needed and point you to the webpages to download them.<\/p>\n<p>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&#8217;t put your host in maintenance mode.<\/p>\n<pre>\r\n<code>#!\/bin\/bash\r\n\r\n#This script takes two arguements, the source folder of all the updates and the xenserver you want to patch\r\n#e.g. xen_updater.sh ~\/Downloads\/xen_updates 172.20.10.74\r\n\r\nif [ $# -eq 2 ]; then\r\n\r\nsource_directory=$1\r\ndestination_directory=\/var\/tmp\/`date -I`\r\ndestination_host=$2\r\n\r\n#first we unzip the files\r\nfor i in `ls $source_directory\/*.zip`; do unzip -n -d $source_directory $i; done\r\n\r\n#then we copy the files to the xenserver\r\necho \"Files will be copied to $destination_host in the directory $destination_directory\"\r\nssh root@$destination_host \"mkdir -p $destination_directory\"\r\nscp $source_directory\/*.xsupdate root@$destination_host:$destination_directory\/\r\n\r\n#time to apply the patches\r\npatches=$(ssh root@$destination_host \"ls $destination_directory\/*.xsupdate\")\r\necho \"patches to be applied:\"\r\necho \"$patches\"\r\n\r\nfor i in $patches; do\r\n        uuid=$(ssh root@${destination_host} \"\/opt\/xensource\/bin\/xe patch-upload file-name=${i} 2&gt;&amp;1 | grep uuid\")\r\n#       echo \"$uuid\"\r\n        uuid_fixed=$(echo $uuid | awk '{print $2}')\r\n#       echo \"$uuid_fixed\"\r\n        echo \"installing: $i uuid:$uuid_fixed\"\r\n        ssh root@$destination_host \"\/opt\/xensource\/bin\/xe patch-pool-apply uuid=${uuid_fixed} 2&gt;&amp;1\"\r\n        echo \"removing: $i to save space\"\r\n        ssh root@$destination_host \"rm $i\"\r\n        done\r\n\r\nelse\r\n        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\"\r\nfi<\/code>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t put [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-330","post","type-post","status-publish","format-standard","hentry","category-virtualization"],"_links":{"self":[{"href":"https:\/\/infinitedisorder.com\/index.php?rest_route=\/wp\/v2\/posts\/330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/infinitedisorder.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/infinitedisorder.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/infinitedisorder.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/infinitedisorder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=330"}],"version-history":[{"count":4,"href":"https:\/\/infinitedisorder.com\/index.php?rest_route=\/wp\/v2\/posts\/330\/revisions"}],"predecessor-version":[{"id":403,"href":"https:\/\/infinitedisorder.com\/index.php?rest_route=\/wp\/v2\/posts\/330\/revisions\/403"}],"wp:attachment":[{"href":"https:\/\/infinitedisorder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/infinitedisorder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/infinitedisorder.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}