Script to create standard computer name

jmltapp1971
New Contributor

Hi we just this week completed our jumpstart and are now looking to starting getting our mac service up and running. As expected it is now due last June and we are rapidly pulling stuff together to ensure the basics to serve our small group of mac users is ready.

To bring macs into line with our PC inventory we are being asked to using the same naming convention.

Currently this is a four character site code for the machine, machine type, 4 digit month and year, and the last 5 characters of the mac id of the machine.

e.g MKEEA1505ABCDE

Im starting to setup a script that prompts the user to enter the site code they work at, and then a month and year of purchase, however as a beginner at scripting I am unsure how I am supposed to pull the mac address from the machine, then remove everything except the final 5 digits?

Once this is devised I was going to rename the machine before running the bind so that the AD records reflect the machine change.

Any help anyone can offer is greatly appreciated.

Thanks

Jason

3 REPLIES 3

jarednichols
Honored Contributor
  1. Which MAC address? Keep in mind that some Macs don't have Ethernet so you're likely talking wifi. However some do have Ethernet (and more than one on the Mac Pro) Then which? Thunderbolt displays have MAC addressed of their own to report. What about those? I guess it begs the question of, "Why part of a MAC address?"

  2. Depending on how fully you're using Casper you may be able to script the entire thing using the API. If you're assigning location and purchase information in a device record you may be able to access it through the API and set host names with zero user interaction.

jmltapp1971
New Contributor

Hey Jared

They want to mirror our PC imaging solution, but as you say not all machines are built equal so I would say as all the system we will use have a wifi adapter we would be best to use that as our standard.

Why part of the mac address - same question we have been asking management for 2 years now, I guess because they wanted a unique identifier for each machine that any of our offices worldwide had access to without maintaining a list or worrying people could double up - ok in principle but a pain when you are typing it compared to our old 4 digit site code and number increasing by one naming convention.

At the moment im really just dipping a toe in, still finding my way around the system. At the moment have the concern of knowing we have machines already out in the wild that we need to find and bring under control.

exno
Contributor

It may be easier to use Serial as the basis for the Apple device Name. We use Department Identifiers at UNC Charlotte. followed by the last 7 of the serial and then a 3 character tag stating whether it is a workstation or a laptop. [ SUAR1234567ALT or SUAR1234567AWS for example ] using the last 7 of the serial offers enough variation that we don't have to worry about name repetition and don't have to worry about the Varied options of MAC Addresses that the devices have.

as @jarednichols stated you may be able to employ the Casper API to do the heavy lifting in the future. but as far as what you are working on now.

What I do is use a script on first run that runs the following to name the machine.

name="$DeptName""$partialsn""$machineType"

Where:
$DeptName is statically set to SUAR
$partialsn is derived from

system_profiler SPHardwareDataType | awk '$1~"Serial" {print $4}' | cut -c6-

and $machineType is basically using an If statement to compare model info to see if it is an iMac, Mac Mini Mac Pro or Macbook (model info is determined based on this

system_profiler SPHardwareDataType | awk '$2~"Identifier" {print $3}'

My script has a static Dept name since i only admin the 340+ apple devices in Student Union Activities and Recreation (SUAR) but I will share this with the Central IT counterpart to me, @dhanes, to share what he is working on. ( It involves Pop ups for the department ID.

- I am @exno or @exnozero on almost everything that exists.