Posted on 08-20-2014 01:30 PM
So we are 1-1 Macbook Airs from 5-12. We attempted to use LAN School last year but had huge issues with computers not showing up in the teachers class lists. I have figured out the reason this was happening, but need some help in finding a way to efficiently fixing it.
So there is the HostName, LocalHostName and ComputerName. The ComputerName and LocalHostName are correct on the machines but on a good number of them the HostName is incorrect. It seems that LAN School and Terminal use the HostName thus why we had issues getting stuff working when they differed from what we thought they were.
Does anyone have any insight on a way to change this en masse?
Solved! Go to Solution.
Posted on 08-20-2014 04:55 PM
based on what you've said, the ComputerName will be the same as the HostName, and the ComputerName's have already been set correctly. so as a test, you'll want to get the ComputerName first
scutil --get ComputerName
if that returns the correct value, then it would only take one line to set the HostName to the same value
scutil --set HostName `scutil --get ComputerName`
I would second @calumhunter with the naming convention, with the concern being you might get some exotic errors with special characters.
Posted on 08-20-2014 02:50 PM
if DNS is accurate for the clients, use the grab the hostname from the hostname command and set it in SystemConfig using scutil --set hostname
Posted on 08-20-2014 02:58 PM
Sorry. I'm not very versed in commands yet. Could you give an example of what it would look like?
Sudo scutil --grab ComputerName
Sudo scutil --set HostName
The computer names are all set correctly now so if it sets the host name to what it grabs I would think it would work..
Posted on 08-20-2014 03:32 PM
depending on how you set your computer names you could just script it
i usually set the computer names based on serial number
theres actually 3 computer names to set
scutil --set ComputerName $serial
scutil --set LocalHostName $serial
scutil --set Hostname $serial
where $serial is the serial number of the machine
from man scutil : Supported preferences include:
ComputerName The user-friendly name for the system.
LocalHostName The local (Bonjour) host name.
HostName The name associated with hostname(1) and gethostname(3).
Posted on 08-20-2014 04:07 PM
We name ours 2015-last-first for example. And the computer name is accurate. And I want 1 script I can push out to all clients that will grab what I want and set it to that for each machine. So I don't have to adjust the script for each machine. If all three names are the same I would think my LAN school wouldn't run into issues. And if somehow that host name changes again it will just fix itself.
Posted on 08-20-2014 04:13 PM
I usually have a launchd script that runs once a day to reset the computer names, i use scutil and set all 3 names the same
I worry about your naming convention, does last-first mean lastname-firstname of the computer user?
How do you envisage getting this information in order to script it?
Posted on 08-20-2014 04:55 PM
based on what you've said, the ComputerName will be the same as the HostName, and the ComputerName's have already been set correctly. so as a test, you'll want to get the ComputerName first
scutil --get ComputerName
if that returns the correct value, then it would only take one line to set the HostName to the same value
scutil --set HostName `scutil --get ComputerName`
I would second @calumhunter with the naming convention, with the concern being you might get some exotic errors with special characters.
Posted on 08-20-2014 07:47 PM
While testing the HostName wasn't correct on certain ones. Sometimes the host name was only 2014-last and left out the rest or in some cases it was something totally different like 2016-last. So it wouldn't show up in LAN school because I was inserting it into the class via machine name (2014-last-first) but the HostName was 2014-last. As soon as I did a scutil --set HostName 2014-last-first, it showed up in LAN School and showed the correct name in terminal. SO if I know the computer names are all correct I just want to make sure HostName and localhostname keep getting prompted to "sync" with the ComputerName and I shouldn't have problems.
We name them this way because it's easy to manage them in our opinion. They are all labeled with their names and it's easy to just search for their graduation year and last-first in jss. We haven't ran into issues with using this convention. If someone's name has an apostrophe we just don't use it in the computer name.
Posted on 08-21-2014 08:28 AM
Thanks htse! I just tested your suggestion and it worked great. Now I just need to figure out how to make that run each day on every machine via casper. I appreciate everyones input!
Posted on 08-21-2014 10:01 AM
@htse wrote:
I would second @calumhunter with the naming convention, with the concern being you might get some exotic errors with special characters.
My bigger concern is your DNS group hunting you down and jumping up and down on top of you for changing a value that is supposed to be set by DNS. But then getting DNS folks to fix things on their end is like dreaming of winning Lotto... ;)
Posted on 08-22-2014 12:27 PM
@donmontalvo: Isn't that why any of this is necessary? Maybe there are OS X reasons as well, but most of the IT guys on "that side" of things tend to dismiss Macs as a rule. We don't even bother asking any more...
Posted on 03-05-2020 08:10 AM
I'm using the following script to rename my macs, but am finding some macs aren't holding onto the rename.
#!/bin/bash
## Laptop or Desktop
TYPE=$(system_profiler SPHardwareDataType | grep -i "MacBook" | wc -l)
[[ $TYPE -gt 0 ]] && T="L" || T="D"
## Get the Serial Number
SERIAL=$(system_profiler SPHardwareDataType | grep -i Serial | grep -i system | awk '{print $NF}' | cut -c5-)
## Put it all together now...
NEWNAME="${T}${SERIAL}"
## Name the computers
scutil --set ComputerName "$NEWNAME"
scutil --set HostName "$NEWNAME"
scutil --set LocalHostName "$NEWNAME"
## Create dummy receipt to mark complete
touch /Library/Receipts/com.company.renameComplete.bom
## Update Inventory
/usr/local/bin/jamf recon