Thursday, May 23, 2013

Updating VMware Tools quickly multiple Linux servers

Ever want to update a bunch of servers quickly?   ESX updates come once every 2-3 months (give or take) and it can be annoying to update all of the servers.  What I do is I will pull down the update and place it on a webserver that is accessible.  You can even change this step to SCP but that involves setting up SSH keys for a simple file grab.

You'll have to initiate the VMtools update at least once, so you can pull down the files from VMWare vSphere.  I place the new updates in the same location each time, symlinking the new files to "vmtools-linux-latest.tar.gz".

Once the initial "prep" is done, I'll usually use SSH from my management server where the SSH keys are already setup to each box then SSH using a text file like so:

cat "/path/to/textfile.txt" | while read a; do ssh root@$a /path/to/; sleep 5; done

I put 'sleep 5' in between each iteration so I can kill the script if I need to.   CTRL+C while the update is running will only kill the update and move onto the next server.

Script "":


WGET="`which wget`"

if [ -z "`which wget`" ]; then
if [ -z "`which yum`" ]; then
echo "YUM utility is not installed.  Will attempt to install."
yum install -y wget

# Only these Linux distro's
RES="`cat /etc/*release |egrep -i \"centos|red hat|fedora|ubuntu\"`"

if [ $EXITCODE -gt 0 ]; then
   echo "Cannot use this utility here (Wrong distro)."

wget --no-check-certificate -q "" -P /tmp
if [ "$?" -gt 0 ]; then
echo "wget of vmtools-linux-latest.tar.gz failed."

rm -rf /tmp/vmware-*
tar xvzf /tmp/vmtools-linux-latest.tar.gz -C /tmp
rm /tmp/vmtools-linux-latest.tar.gz
/tmp/vmware-tools-distrib/ -default
rm -rf /tmp/vmware-*

echo "vmtools updated on `hostname`" | mailx -s "`hostname`: vmtools updated"

No comments:

Post a Comment