Rename Computers Based on Serial Number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 05-11-2011 09:38 AM
Here is my problem. I want to wright a script to rename my computer based on the serial number of the computer and also in include a prefix of GISD-. I have found out the you can do a grep on the serial number from system profiler but that is as far as I can get.
Please Help
Brian Weeks

Brian Weeks
Systems Engineer
Groesbeck ISD
1202 N. Ellis
Groesbeck, TX
Office: (254) 729-4130
Email: bweeks at groesbeckisd.net<mailto:bweeks at groesbeckisd.net>
Website: http://www.groesbeckisd.net<https://gisdexch.groesbeck.k12.tx.us/owa/redir.aspx?C=39a81fe758b64100bcaaf454287d183f&URL=http%3a%2f%2fwww.groesbeckisd.net>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 05-11-2011 09:44 AM
Here's an example:
#!/bin/bash
base="GISD-"
tld="example.com"
serial=/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Serial Number (system)/ {print $NF}'
/usr/sbin/scutil --set ComputerName $base$serial
/usr/sbin/scutil --set LocalHostName $base$serial
/usr/sbin/scutil --set HostName $base$serial.tld
Practice writing scripts so you can get more familiar with this stuff. If you're managing Macs, you need to be comfortable with the command line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 05-11-2011 09:49 AM
That line should read:
/usr/sbin/scutil --set HostName $base$serial.$tld
Or better yet:
/usr/sbin/scutil --set HostName "${base}${serial}.${tld}"
This way ensures nothing unexpected happens, when expanding the variables or running the command. Be sure to test it, of course.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 05-11-2011 09:53 AM
True enough.
Also, never just run something you've copied and pasted from someone else without understanding what it does…
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 01-27-2012 08:25 AM
I was trying to use a script similar to this to set hostname at deploy time, but when testing I noticed that it doesn't change the remote login name (under system preferences|Sharing) Does anyone know how to change that name too?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 05-07-2013 02:43 AM
You could just do this with the JAMF binary
#!/bin/sh
/usr/sbin/jamf setComputerName -useSerialNumber
Even more options:
Usage: jamf setComputerName [-target <target volume>] [-name <name>]
[-useMACAddress] [-useSerialNumber] [-suffix <suffix>]
[-prefix <prefix>] [-fromFile <path to file>]
-target The target drive to set the name on
-name The new name for the computer
-useMACAddress Generate the name using the MAC Address
-useSerialNumber Generate the name using the Serial Number
-prefix Add this prefix to the MAC Address or Serial Number
-suffix Add this suffix to the MAC Address or Serial Number
-fromFile The path to a CSV file containing the computer's MAC Address or Serial Number followed by the desired name

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-29-2015 05:45 PM
I'm looking to automate our naming convention during Casper Imaging. Here is what I have now, I expect to have this run At Reboot.
My issue is the Suffix is not recorded. I've attempted to escape the dash with double quotes, double dash, forward slash, and backslash - none of which do as I like. Any Ideas?
#!/bin/sh
/usr/sbin/jamf setComputerName -useSerialNumber -prefix 'LT-' -suffix '-M'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 11-30-2015 12:44 PM
Did anyone get this to work? Also interested of naming to the same similar convention. Would like to hear opinions on what is the best avenue to take on this process.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 12-01-2015 08:34 AM
I tested on version 9.81 and it seems like some sort of bug.
acodega:~ adamcodega$ sudo jamf setComputerName -useSerialNumber -prefix 'LT-' -suffix 'M'
Set Computer Name to LT-C02N940YG5RPM
acodega:~ adamcodega$ sudo jamf setComputerName -useSerialNumber -prefix 'LT-' -suffix '.M'
Set Computer Name to LT-C02N940YG5RP.M
acodega:~ adamcodega$ sudo jamf setComputerName -useSerialNumber -prefix 'LT-' -suffix '-M'
Set Computer Name to LT-C02N940YG5RP
acodega:~ adamcodega$ sudo jamf setComputerName -useSerialNumber -prefix 'LT-' -suffix '--M'
Set Computer Name to LT-C02N940YG5RP
acodega:~ adamcodega$ sudo jamf setComputerName -useSerialNumber -prefix 'LT-' -suffix '/M'
Set Computer Name to LT-C02N940YG5RP/M
Did anyone contact Support?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 12-01-2015 08:56 AM
FWIW, I did the same test as @adamcodega above using 9.73 and see the same issue. So its not a new bug in 9.81 so you know. Its dropping the suffix if there is a hyphen at the start of the suffix text. I tried it with double quotes surrounding the text and saw the same issue, so it doesn't have anything to do with the quotes. Seems support needs to be contacted so they can reproduce it and create a defect for it.
