The Virtualization Room

Apr 4 2007   8:32AM GMT

Getting ESX 3.0.0 and 3.0.1 updates

Kutz Profile: Akutz

It can be a real hassle to download updates for ESX 3.0.0 and 3.0.1. Wouldn’t it be nice if there was some program that could take care of this for you? Now there is! Introducing my patented (not really) chk4updates script. Using arcane majiks and other-wordly sorceries, I have divined through intense enchanting a process by which you can grab all available updates for ESX versions 3.0.0 and 3.0.1. I have included the script inline below, and you can also grab it from www.lostcreations.com.

#!/bin/bash

#
# debug level. set to ’1′ to have extra debugging
# information sent to stdout.
#
DEBUG=”0″

#
# the version of esx server to download patches for
# valid values are ’3.0.0′ and ’3.0.1′
#
ESX_VERSION=”3.0.1″

#
# set to ’1′ to download tarballs
# set to ’0′ to just have a message printed to stdout
#
DOWNLOAD_TARBALLS=”1″

#
# the directory to place the downloaded tarballs in
#
PATCH_OUTPUT_DIR=”/home/akutz/isos/vmware/esx_updates/”

#
# get a list of the already downloaded patch files
#
DOWNLOADED_PATCH_FILES=`ls $PATCH_OUTPUT_DIR`

if [ "$DEBUG" == "1" ]
then
echo “ESX_VERSION=$ESX_VERSION”
echo “DOWNLOAD_TARBALLS=$DOWNLOAD_TARBALLS”
echo “PATCH_OUTPUT_DIR=$PATCH_OUTPUT_DIR”
fi

# get a list of the updates
wget –quiet http://www.vmware.com/download/vi/vi3_patches.html

# parse the updates list for the actual links
PATCH_LINKS=`cat vi3_patches.html

| egrep -io “http://www.vmware.com/support/vi3/doc/esx-[[:digit:]]*-patch.html”`

# remove vi3_patches.html
rm -f vi3_patches.html

# iterate through the patch links
for LINK in $PATCH_LINKS
do
# get the patch information
wget -q $LINK

# parse the actual file name from the patch link
LINK_FILE=`echo $LINK | sed “s/(.*)(/)([^/]*.html)/3/g”`

# determine if this is an esx 3.0.0 or 3.0.1 patch
egrep -ioq “Download Patch ESX-[[:digit:]]*
for VMware ESX Server 3.0.0″ $LINK_FILE
IS_300=”$?”
egrep -ioq “Download Patch ESX-[[:digit:]]*
for VMware ESX Server 3.0.1″ $LINK_FILE
IS_301=”$?”

GET_TARBALL=”0″

# 3.0.0
if [ "$IS_300" == "0" ] &&
[ "$ESX_VERSION" == "3.0.0" ]
then
GET_TARBALL=”1″
fi

# 3.0.1
if [ "$IS_301" == "0" ]
&& [ "$ESX_VERSION" == "3.0.1" ]
then
GET_TARBALL=”1″
fi

if [ "$DEBUG" == "1" ]
then
echo
“IS_300=$IS_300,IS_301=$IS_301,GET_TARBALL=$GET_TARBALL”
fi

if [ "$GET_TARBALL" == "1" ]
then
#
# get the link to the tarball we want to download
#
TARBALL_LINK=`cat $LINK_FILE | egrep -io “http.*gz”`

#
# strip the extraneous stuff of the link
# so that only the name of the tarball remains
#
TARBALL_LINK_FILE=`echo $TARBALL_LINK | sed “s/(.*)(/)([^/]*gz)/3/g”`

#
# parse the patch release date from the patch html
#
PATCH_RELEASE_DATE=`cat $LINK_FILE | egrep -io “<b>released .*</b>” |
sed “s/(<b>released )(.*)(</b>)/2/gi”`

#
# get the name of the directory that is
# created once the patch is decompressed
#
DECOMP_PATCH_DIR=`echo $TARBALL_LINK_FILE
| sed “s/(.*)(.[^.]*$)/1/gi”`

#
# prepend the patch release date to the decompressed directory
#
DECOMP_PATCH_DIR_W_DATE=”`date
-d \”$PATCH_RELEASE_DATE\” \”+%Y%m%d\”`-$DECOMP_PATCH_DIR”

# determine if the patch has already been downloaded by
# comparing the name of the patch to the files that
# exist in the output directory
echo $DOWNLOADED_PATCH_FILES |
egrep -ioq $TARBALL_LINK_FILE
ALREADY_DOWNLOADED=”$?”

if [ "$DEBUG" == "1" ]
then
echo
“TARBALL_LINK_FILE=$TARBALL_LINK_FILE,ALREADY_DOWNLOADED=$ALREADY_DOWNLOADED”
fi

if [ "$ALREADY_DOWNLOADED" != "0" ]
&& [ "$TARBALL_LINK" != "" ]
then

if [ "$DOWNLOAD_TARBALLS" == "1" ]
then
echo “fetching $TARBALL_LINK_FILE …”

# fetch the patch
wget -q $TARBALL_LINK

# move the patch to the outpdir directory
mv $TARBALL_LINK_FILE $PATCH_OUTPUT_DIR

# change the working directory to the output directory
cd $PATCH_OUTPUT_DIR

# decompress the patch
tar xzf $TARBALL_LINK_FILE

# rename the decompressed patch dir to include the
# patch release date
mv $DECOMP_PATCH_DIR $DECOMP_PATCH_DIR_W_DATE

# remove the patch tarball
rm -f $TARBALL_LINK_FILE

# change into the previous working directory
cd -
fi
fi
fi

# remove the patch information
rm -f $LINK_FILE
done

14  Comments on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Akutz
    I apologize, but I am not very familiar with Linux and have a couple of questions. First, it appears in your code, you state: # # the directory to place the downloaded tarballs in # PATCH_OUTPUT_DIR=”/home/akutz/isos/vmware/esx_updates/” My ESX hosts do not have this directory as I do not have a user 'akutz'. Can this directory be changed to /var/updates as VMWare suggests? Second, after I copy this code, what do I save it as? Thanks for your assistance.
    0 pointsBadges:
    report
  • Akutz
    You sure can. It can be any directory, that just happens to be where I store my ESX patches on my file server.
    640 pointsBadges:
    report
  • Akutz
    Sorry, I realize I did not answer both of your questions. I would save the script to /usr/local/bin/chk4updates and then make it executable by typing 'chmod 0770 /usr/local/bin/chk4updates'. It can be stored anywhere though.
    0 pointsBadges:
    report
  • Akutz
    Thank you for this arcane majiks and other-wordly sorceries script. It has help immensely. Might want to include the egrep -ioq “Download Bundle ESX-[[:digit:]]* for VMware ESX Server 3.0.1″ $LINK_FILE IS_301=”$?” This will ensure any bundled patches also get downloaded.
    0 pointsBadges:
    report
  • Akutz
    Just a note for those who run this on an ESX server, wget is not included as part of the VI3 install. It will work when compiled from source but is not officially supported by VMware.
    0 pointsBadges:
    report
  • Akutz
    Hi, I think there is something wrong with your script. I tested it and it works find, but it allways downloads all patches, if they exist or not makes no difference. I think there is something wrong with the IF command near the wget command. What I tried: start first time -> wonderfull, it downloads all delete 2 of the unpacked directories start second time -> it still downloads all again do nothing start third time -> it also downloads all again At the moment I have no idea how to fix that, but if anybody does, that would be fine :-) Regards, Chris
    0 pointsBadges:
    report
  • Akutz
    I removed the following lines, I was having the same issue. Also added egrep -io "Download "\(Patch\|Bundle\)" ESX-[[:digit:]]* for VMware ESX Server 3.0.1" $LINK_FILE IS_301="$?" As extra step to get the bundled file. I am posting the entire script with my modifications. Still the majority of the work done by Andrew. Thanks again! #!/bin/bash # # # Also adds a check to make sure the server is in Maintenance Mode # # #puts ESX in maintenance mode # vimsh -n -e /hostsvc/maintenance_mode_enter # #waits for virtual machines to migrate may need to be adjusted depending #also test fail over for HA :) # sleep 1 echo Checking to see if host is in maintenance mode... if ['vmish -n -e hostsvc/runtimeinfo | grep "inMaintenanceMode = false" | wc -l' -eq 0] then echo Host must be in Maintenance Mode before patching... echo Now Exiting... exit fi echo Host is in maintenance mode. Continuing patch script... if [ -e "/var/updates" ] then echo "Updates Directory Exists" else echo "Updates Directory Not Found - Creating directory" cd /var mkdir updates fi echo "Now downloading files from vmware" echo "This may take a couple of minutes" echo "starting..." esxcfg-firewall --allowIncoming esxcfg-firewall --allowOutgoing mv /var/tmp/ESX*.tgz /var/updates # # debug level. set to '1' to have extra debugging # information sent to stdout. # DEBUG="1" # # the version of esx server to download patches for # valid values are '3.0.0' and '3.0.1' # ESX_VERSION="3.0.1" # # set to '1' to download tarballs # set to '0' to just have a message printed to stdout # DOWNLOAD_TARBALLS="1" PATCH_OUTPUT_DIR="/var/updates" # # get a list of the already downloaded patch files # DOWNLOADED_PATCH_FILES=`ls $PATCH_OUTPUT_DIR` if [ "$DEBUG" == "1" ] then echo "ESX_VERSION=$ESX_VERSION" echo "DOWNLOAD_TARBALLS=$DOWNLOAD_TARBALLS" echo "PATCH_OUTPUT_DIR=$PATCH_OUTPUT_DIR" fi # get a list of the updates wget --quiet http://www.vmware.com/download/vi/vi3_patches.html # parse the updates list for the actual links PATCH_LINKS=`cat vi3_patches.html | egrep -io "http://www.vmware.com/support/vi3/doc/esx-[[:digit:]]*-patch.html"` # remove vi3_patches.html rm -f vi3_patches.html # iterate through the patch links for LINK in $PATCH_LINKS do # get the patch information wget -q $LINK # parse the actual file name from the patch link LINK_FILE=`echo $LINK | sed "s/\(.*\)\(\/\)\([^\/]*.html\)/\3/g"` # determine if this is an esx 3.0.0 or 3.0.1 patch egrep -io "Download Patch ESX-[[:digit:]]* for VMware ESX Server 3.0.0" $LINK_FILE IS_300="$?" egrep -io "Download "\(Patch\|Bundle\)" ESX-[[:digit:]]* for VMware ESX Server 3.0.1" $LINK_FILE IS_301="$?" # determine if the patch has already been downloaded by # comparing the name of the patch to the files that # exist in the output directory echo $DOWNLOADED_PATCH_FILES | egrep -ioq $TARBALL_LINK_FILE ALREADY_DOWNLOADED="$?" if [ "$DEBUG" == "1" ] then echo "TARBALL_LINK_FILE=$TARBALL_LINK_FILE,ALREADY_DOWNLOADED=$ALREADY_DOWNLOADED" fi GET_TARBALL="0" # 3.0.0 if [ "$IS_300" == "0" ] && [ "$ESX_VERSION" == "3.0.0" ] then GET_TARBALL="1" fi # 3.0.1 if [ "$IS_301" == "0" ] && [ "$ESX_VERSION" == "3.0.1" ] then GET_TARBALL="1" fi if [ "$DEBUG" == "1" ] then echo "IS_300=$IS_300,IS_301=$IS_301,GET_TARBALL=$GET_TARBALL" fi if [ "$GET_TARBALL" == "1" ] then # # get the link to the tarball we want to download # TARBALL_LINK=`cat $LINK_FILE | egrep -io "http.*gz"` # # strip the extraneous stuff of the link so that only the name of the tarball remains # TARBALL_LINK_FILE=`echo $TARBALL_LINK | sed "s/\(.*\)\(\/\)\([^\/]*gz\)/\3/g"` # # parse the patch release date from the patch html # PATCH_RELEASE_DATE=`cat $LINK_FILE | egrep -io "released .*" | sed "s/\(released \)\(.*\)\(\)/\2/gi"` # # get the name of the directory that is created once the patch is decompressed # DECOMP_PATCH_DIR=`echo $TARBALL_LINK_FILE | sed "s/\(.*\)\(\.[^\.]*$\)/\1/gi"` # # prepend the patch release date to the decompressed directory # DECOMP_PATCH_DIR_W_DATE="`date -d \"$PATCH_RELEASE_DATE\" \"+%Y%m%d\"`-$DECOMP_PATCH_DIR" if [ "$ALREADY_DOWNLOADED" != "0" ] && [ "$TARBALL_LINK" != "" ] then if [ "$DOWNLOAD_TARBALLS" == "1" ] then echo "fetching $TARBALL_LINK_FILE ..." # fetch the patch wget -q $TARBALL_LINK # move the patch to the outpdir directory mv $TARBALL_LINK_FILE $PATCH_OUTPUT_DIR # change the working directory to the output directory cd $PATCH_OUTPUT_DIR fi fi fi # remove the patch information rm -f $LINK_FILE
    0 pointsBadges:
    report
  • Akutz
    Thanks David! I am going to be posting the script and keeping it updated on my own blog. I will be sure to incorporate your changes and acknowledge you as the author. Thanks again!
    0 pointsBadges:
    report
  • Akutz
    Hi, thanks for the fast answer. I understood you, that in your last post, you copied the hole script. This script is also not working perfect. At first I'm missing the option to unpack all the tar files. I would prefere to unpack all TARs and delete them. Then the script should check before it starts to download a tar file, if there is already a directory with the same name. For this we should disable the rename option, which renames the unpacked directories with the date after the original name. For me that means: - check if there is a directory with the same name like a patch, if so, don't download. If not, download the tar, unpack it and delete it. Hopefully you understand what I mean. My bash knowledge is not the best, so maybe you can script my ideas? If you have some others ideas, which can be helpfull, feel free to add them. Best regards, Chris
    0 pointsBadges:
    report
  • Akutz
    Another thing: It would be very nice, if you can store the file on a webserver, because if you copy the code from this webpage, it adds a lot of strange symbols, which you have remove by hand... :-( If you don't have a webspace, please let me know and I will save it on my server and post the link here. You can reach me by email angoletti1@yahoo.de Thanks
    0 pointsBadges:
    report
  • Akutz
    Chris, The script *is* stored on a webserver. The link is the original article.
    0 pointsBadges:
    report
  • Akutz
    Sorry about that, not sure how the formatting got in the script. In response, 1 - At first I’m missing the option to unpack all the tar files. I would prefer to unpack all TARs and delete them. I have another script; thanks vmware forum (I will send also to you and Mr. Kutz) to perform this process, it could be incorporated but would require some additional bash script work. Coming to a bash shell near you soon. This script has not yet been rated. In its current iteration it checks to see if the tar exists, not the directory. This is due to some of the tars being bundled; well, at least it made it easier. I will send you a file via e-mail to post. Also, most scripts I have run into remove/delete the file\directory after patching. Probably better to keep the .tgz(they are compressed) for future patch download comparision. There are a lot of variations on this idea. Here are a few links that have a few different spins. http://tinyurl.com/yr52bu http://tinyurl.com/29whuz A great Vmware spot http://virtrix.blogspot.com
    0 pointsBadges:
    report
  • Akutz
    Hi VmWarriors, Script above is nice but a bit buggy and difficult to use. Take a look at my scripts on http://www.serverchief.com Screenshots and easy instruction is available as well. Good luck ServerChief..
    0 pointsBadges:
    report
  • Akutz
    ServerChief, that's nice of you to come to someone elses site and not offer any help, just pimp out your own stuff that doesn't work on a default install of 3.0.1 I'd like to modify this script to reference a local webstore instead of downloading all of the files all over again. I'm still new to Shell so this is proving a bit difficult. Any suggestions? I have a .txt file with the patches listed in it, and I have a folder for each patch. I bascially need to go get a directory list from the web server then loop through each and install the patches as it comes to them.
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: