Novell Home

Using the PC Asset Tag number in the PC Name for Imaging

Novell Cool Solutions: Feature
By Pete Demers

Digg This - Slashdot This

Posted: 12 Jan 2006
 

ENVIRONMENT: Using a ZENworks 7 Boot CD and PXE files.
Using DMIDECODE version 2.7
Note: I also add the Linux executables files CLEAR and MORE to my Boot Image.

PROBLEM: You want to use the PC's Asset Tag or Serial Number in the PC name using ZENworks Imaging.

SOLUTION: Add the Linux executable DMIDECODE to your ZENworks Boot environment:

ZEN Boot CD
Using a program like UlrtaISO, open the BOOTCD.ISO and add the file DMIDECODE to the folder /addfiles/bin

PXE Boot
Use a TFTP statement at the beginning of the imaging script to download additional files when needed.

echo "Getting files from TFTP server...."
cd /bin
tftp -m binary $PROXYADDR -c get clear
chmod +x clear

Note: TFTP seems to have a limit on file name length. Make sure that the files that you are downloading have names that are not longer than 8 characters.

Example

I set the environment variable in the script like this:
SYSTEMSERIAL='dmidecode -s chassis-serial-number'

DMIDECODE [OPTIONS]

-q, --quiet
Be less verbose. Unknown, inactive and OEM-specific entries are not displayed. Meta-data and handle references are hidden.

-s, --string KEYWORD
Only display the value of the DMI string identified by KEYWORD. KEYWORD must be a keyword from the following list: bios-vendor, bios-version, bios-release-date, system-manufacturer, system-product-name, system-version, system-serial-number, base?board-manufacturer, baseboard-product-name, base?board-version, baseboard-serial-number, baseboard-asset-tag, chassis-manufacturer, chassis-version, chassis-serial-number, chassis-asset-tag, proces?sor-manufacturer, processor-version. Each keyword corresponds to a given DMI type and a given offset within this entry type. Not all strings may be meaningful or even defined on all systems. Some keywords may return more than one result on some systems (e.g. Processor-version on a multi-processor system). If KEYWORD is not provided or not valid, a list of all valid keywords is printed and dmidecode exits with an error. This option cannot be used more than once, and implies --quiet. Mutually exclusive with --type and --dump.

-t, --type TYPE
Only display the entries of type TYPE. TYPE can be either a DMI type number, or a comma-separated list of type numbers, or a keyword from the following list: bios, system, baseboard, chassis, processor, memory, cache, connector, slot. Refer to the DMI TYPES section below for details. If this option issued more than once, the set of displayed entries will be the union of all the given types. If TYPE is not provided or not valid, a list of all valid keywords is printed and dmidecode exits with an error. Mutually exclusive with --string.

-u, --dump
Do not decode the entries; dump their contents as hexadecimal instead. Note that this is still a text output; no binary data will be thrown upon you. The strings attached to each entry are displayed as both hexadecimal and ASCII. This option is mainly useful for debugging. Mutually exclusive with --string.

Using additional scripting, the length of the Workstation Name is verified and additional elements are added to the name.

Below is an example of our current script:
(If anyone has suggestions to improve or optimize this script, please let me know.)

#!/bin/bash
# 
# Prompted Workstation Imaging Script
#
# Created by: Pete Demers (pete.demers@fairchildsemi.com)
# Based on  "Making a Scripted Image ..." By" Jesse David Hollington
# Liberally adapted from many other Cool Solutions
#

#echo "Getting files from TFTP server...."
#cd /bin
#tftp -m binary $PROXYADDR -c get clear
#chmod +x clear

clear

BASEPATH="vol1/image/prod/XP"
ADDONPATH="vol1/image/prod/addon"
SITEPATH="vol1/image/site"
IMAGEVERSION=2.20.102505
SITECODE="HQ"

# Pull Workstation Name from ZIS
#Because ZEN 7 adds trailing crap, get just the first line using the head command.
echo "Reading ZEN Image Safe Data...."
ZISNAME=`zisview Name|head -n 1`
ZISJUSTIMAGED=`zisview JustImaged|head -n 1`
ZISSCRIPTEDIMAGE=`zisview ScriptedImage|head -n 1`
ZISLASTBASEIMAGE=`zisview LastBaseImage|head -n 1`
ZISOBJECTDN=`zisview ObjectDN|head -n 1`
ZISTREE=`zisview Tree|head -n 1`
ZISWORKGROUP=`zisview WorkGroup|head -n 1`
ZISSID=`zisview SID|head -n 1`
ZISWORKSTATIONID=`zisview WorkstationID|head -n 1`
ZISDHCP=`zisview DHCP|head -n 1`
ZISIP=`zisview IP|head -n 1`
ZISGATEWAY=`zisview Gateway|head -n 1`
ZISMASK=`zisview Mask|head -n 1`
ZISDNSSERVERCOUNT=`zisview DNSServerCount|head -n 1`
ZISDNSSUFFIX=`zisview DNSSuffix|head -n 1`
ZISDNSHOSTNAME=`zisview DNSHostName|head -n 1`

echo "Reading chassis serial number...."
SYSTEMSERIAL=`dmidecode -s chassis-serial-number`

# Test it ZIS name exists
if test ! $ZISNAME; then
	
	echo ""
	# No Workstation Name found in ZIS so prompt for name
	echo -e "No image-safe data found." 
	echo -e "Assumed to be a new workstation.\n" 

 	while [ ${#WSNAME} -lt 3 ]; do

		while test ! $WSNAME; do 
			echo -n "Enter the workstation name: " 
			read WSNAME; 
		done; 

		zisedit -c > /dev/nul
		WSNAME=`echo "$WSNAME" | tr "[a-z]" "[A-Z]"`

		if [ "$WSNAME" = "LOANER" ] || [ "$WSNAME" = "SPARE" ] || [ "$WSNAME" = "LNR" ] || [ "$WSNAME" = "SPR" ]; then
				
			#Check to see if we need to construct the WS name from Serial

			#Shorten the name to fit with in the construct.
			if [ "$WSNAME" = "LOANER" ]; then
				WSNAME=LNR
			elif [ "$WSNAME" = "SPARE" ]; then 
				WSNAME=SPR
			fi

			#Check to see if site code was specified, if not then get it.
			if test -z $SITECODE; then
				while test ! $SITECODE; do 
					echo -n "Enter two char Site Code (HQ, FM, MT, etc...): "
					read SITECODE;
					if [ ${#SITECODE} -gt 2 ] ; then
						SITECODE=""
						echo "Site Code names must be 2 characters or less"
					fi
				done;

				SITECODE=`echo "$SITECODE" | tr "[a-z]" "[A-Z]"`
			fi

			#Determine if we get a value worth using, if not prompt for it.
			if [ "$SYSTEMSERIAL" <> "Not Specified" ]; then
				WSNAME=$WSNAME-$SYSTEMSERIAL-$SITECODE
			else
				while test ! $SYSTEMSERIAL; do 
					echo -e "Script was not able to get Asset Tag!"
					echo -e "Please report this problem to the Novell Server Group"
					echo -n "Please enter Asset Tag : "
				read SYSTEMSERIAL;
				done;
				WSNAME=$WSNAME-$SYSTEMASSET-$SITECODE
			fi
		fi

	#Check to ensure workstation name is below max characters

	if [ ${#WSNAME} -gt 15 ] || [ ${#WSNAME} -lt 3 ]; then
		echo ""
		echo -e "\033[0;31mWorkstation name too long/short! Workstation Name is ${#WSNAME} characters\033[0;37m"
		WSNAME=""
		echo -e "\033[0;31mWorkstation name must be greater than 3 characters and less than 15!\033[0;37m"
		echo ""
	fi

	done;

	zisedit Name=$WSNAME > /dev/nul;
	ZISNAM				#Check to see if we need to construct the WS name from Serial

				#Shorten the name to fit with in the construct.
				if [ "$WSNAME" = "LOANER" ]; then
					WSNAME=LNR
				elif [ "$WSNAME" = "SPARE" ]; then 
					WSNAME=SPR
				fi

				#Check to see if site code was specified, if not then get it.
				if test -z $SITECODE; then
					while test ! $SITECODE; do 
						echo -n "Enter two char Site Code (HQ, FM, MT, etc...): "
						read SITECODE;
						if [ ${#SITECODE} -gt 2 ] ; then
							SITECODE=""
							echo "Site Code names must be 2 characters or less"
						fi
					done;

					SITECODE=`echo "$SITECODE" | tr "[a-z]" "[A-Z]"`
				fi

				#Determine if we get a value worth using, if not prompt for it.
				if [ "$SYSTEMSERIAL" <> "Not Specified" ]; then
					WSNAME=$WSNAME-$SYSTEMSERIAL-$SITECODE
				else
					while test ! $SYSTEMSERIAL; do 
						echo -e "Script was not able to get Asset Tag!"
						echo -e "Please report this problem to the Novell Server Group"
						echo -n "Please enter Asset Tag : "
					read SYSTEMSERIAL;
					done;
					WSNAME=$WSNAME-$SYSTEMASSET-$SITECODE
				fi
			fi
		#Check to ensure workstation name is below max characters

		if [ ${#WSNAME} -gt 15 ] || [ ${#WSNAME} -lt 3 ]; then
			echo ""
			echo -e "\033[0;31mWorkstation name too long/short! Workstation Name is ${#WSNAME} characters\033[0;37m"
			WSNAME=""
			echo -e "\033[0;31mWorkstation name must be greater than 3 characters and less than 15!\033[0;37m"
			echo ""
		fi

		done;

		zisedit Name=$WSNAME > /dev/nul
		ZISNAME=`zisview Name|head -n 1`;
	fi	
fi

#sleep 10
clear
echo "*****************************************************************************"
echo -e "Workstation Name : $ZISNAME"
echo -e "Just Imaged: $ZISJUSTIMAGED"
echo -e "Scripted Image : $ZISSCRIPTEDIMAGE"
echo -e "Last Base Image : $ZISLASTBASEIMAGE"
echo ""

echo -e "Novell Tree : $ZISTREE"
echo -e "Workstation Object : $ZISOBJECTDN"
echo ""
echo -e "Workgroup : $ZISWORKGROUP"
echo -e "Workstation SID : $ZISSID"
echo -e "Workstation ID : $ZISWORKSTATIONID"
echo ""

echo -e "DHCP : $ZISDHCP"

if [ "$ZISDHCP" = "Off" ]; then
	echo -e "  IP Address  : $ZISIP"
	echo -e "  IP Gateway  : $ZISGATEWAY"
	echo -e "  Subnet Mask : $ZISMASK"
	echo -e "  DNS Suffix   : $ZISDNSSUFFIX"
	echo -e "  DNS HostName : $ZISDNSHOSTNAME"
	echo -e "  DNS Server Count : $ZISDNSSERVERCOUNT	img rp $PROXYADDR //$PROXYADDR/$ADDONPATH/software/CyberLinkPowerDVD5_5.zmg
	img rp $PROXYADDR //$PROXYADDR/$ADDONPATH/software/Flash10.zmg
	img rp $PROXYADDR //$PROXYADDR/$ADDONPATH/software/iPass33.zmg
	img rp $PROXYADDR //$PROXYADDR/$ADDONPATH/software/ipp405.zmg
	img rp $PROXYADDR //$PROXYADDR/$ADDONPATH/software/JRE1_42_04.zmg
	img rp $PROXYADDR //$PROXYADDR/$ADDONPATH/software/SonicRecordNow73.zmg
	img rp $PROXYADDR //$PROXYADDR/$ADDONPATH/software/VPN5_0_1_110.zmg

	img rp $PROXYADDR //$PROXYADDR/$ADDONPATH/ImageProcessChangev2_2_AutoName.zmg
	img rp $PROXYADDR //$PROXYADDR/$SITEPATH/SiteRunOnce.zmg
fi

reboot ?f

If you have any questions you may contact Pete at pete.demers@fairchildsemi.com


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell