Change Hostid Script.

Hi Folks'

Wrote this script earlier and said to hicksd8 that I'd post it here, it's just a quick and dirty hack to change the hostid of a global zone on a Solaris Virtual running under a hypervisor - manes and ID changed to protect the inocent.

#!/usr/bin/bash
################################################################################
#
# Script to change hostid on a Solaris 11.1 virtual machine running in VMWare
# where there is a requirement for the hostid of the GLOBAL zone to be changed.
# If changing the hostid of a non global zone this can be done using the normal
# process for a Solaris Zone.
#
################################################################################
################################################################################
#
# Title         -       Set Hostid
#
# Author        -       Dave Hoojikaflip
# Date          -       19/04/2014
# Version       -       1.00.01
#
################################################################################
# Dependencies.
#
# 1     This script requires standard  Solaris 11.1 install.
#
# 2     This script required the standard logging utility to be in the BINDIR
#
################################################################################
# Deprecated.
#
# 1     No longer requires the hostid to be passed as an argument.
#
################################################################################
#
# History - Please enter changes here - latest at the top.
#
################################################################################
#
# Version 1.00.01
#
# Hostid now embedded in the script, tested on license servers with Solaris 11.1
# and the CAD environment set in anticipation of consolidation excercise.
#
# Version 1.00.00
#
# Created to set hostid manually, will implement as a service with logging when
# time allows. The desired hostid must be passed as an argument, will set a
# default option in a later version of the script.
#
################################################################################

################################################################################
#
# Set Globals here.
#
################################################################################

MAX=0
THISPROG=/usr/local/bin/set_hostid.sh
NAME=`uname -n`
DATE=`date +%m/%d/%y`
export NAME DATE THISPROG MAX

OTYP=`uname`
BINDIR=/usr/local/bin
LIBDIR=/usr/local/lib
TMPDIR=/tmp
MAILFILE=/tmp/hostid_set_ok.txt
export OTYP BINDIR LIBDIR TMPDIR MAILFILE

################################################################################
#
# Set the required hostid below.
#
################################################################################

HOSTID=0x80cfe985

export HOSTID

################################################################################
#
# Setup the logging functions.
#
################################################################################

STARTMSG ()
{
/usr/local/bin/logger.sh "${THISPROG} $* STARTED"
}

MSG ()
{
/usr/local/bin/logger.sh "${THISPROG} $*"
}

JMSG ()
{
echo "${THISPROG} $*"
}

ERR ()
{
/usr/local/bin/logger.sh "${THISPROG} $*"
/usr/local/bin/logger.sh "${THISPROG} FAILS"
exit 1
}

ENDMSG ()
{
/usr/local/bin/logger.sh "${THISPROG} COMPLETED"
exit 0
}
################################################################################
#
# Set the hostid for a Solaris Global in a virtual under VSphere, should work
# for most Hypervisors.
#
################################################################################
################################################################################
#
# Put the start message in the logfile allong with calling script and time stamp.
#
################################################################################

STARTMSG

################################################################################
#
# Print the screen message to advise user of actions.
#
################################################################################

echo "This licence server replaces edinburgh.noobab.com - with a hostid of 80cfe985"
echo ""

################################################################################
#
# Set the hostid here and test results, use standard day log for output.
#
################################################################################
################################################################################
#
# Convert the Hex hostid variable to a sequence of Ascii.
#
################################################################################

ascii=`echo $((${HOSTID})) | od -t x1 | head -1 | cut -f2-100 -d" "`

if [[ $? != "0" ]]
        then
                MSG "Conversion of Hex string to Ascii has failed."
                ERR "Check that the HOSTID variable is formatted as 0xFFFFFFFF."
        else
                MSG "Successful conversion Hex to Ascii."
fi

################################################################################
#
# Open the serial module for writing and insert the new hostid.
#
################################################################################

echo "hw_serial/v "${ascii:0:$((${#ascii}-2))}"00 0" | mdb -kw

if [[ $? != "0" ]]
        then
                MSG "Inserion of hostid in core module has failed."
                ERR "Check that the module debugger is installed."
        else
                MSG "Successful hostid change."
fi

################################################################################
#
# Print the new hostid on the screen and output to logfile.
#
################################################################################

JMSG "hostid is now set to: "`hostid`
MSG "hostid is now set to: "`hostid`
ENDMSG