Posted on 10-05-2018 03:10 PM
I am really new to scripting, and i was thinking if i can make a script for computer name, Localhostname, and hostname.
i used to just open terminal then
type
sudo scutil --set Computer Name XXX
sudo scutil --set LocalHostName
sudo scutil --set HostName
pleae help me if below script is okay!
thank you
setName=scutil --set ComputerName
scutil --set LocalHostName ${setName}
scutil --set HostName ${setName}
echo HostName and LocalHostName set to ${setName}
exit 0
Posted on 10-05-2018 03:29 PM
Oh boy. Lots of stuff there will break your script.
First, you need a way for the script to know what name you want. Besides that, the script would look more like this:
#!/bin/sh
scutil --set ComputerName $setName
scutil --set HostName $setName
scutil --set LocalHostName $setName
If you are trying to read in the ComputerName and set that for the other two names, that would look like:
#!/bin/sh
setName=$(scutil --get ComputerName)
scutil --set HostName $setName
scutil --set LocalHostName $setName
Posted on 10-06-2018 06:37 AM
This is what mines looks like:
definedComputerName="/usr/sbin/system_profiler SPHardwareDataType | awk '/Serial Number/ { print $NF }' | rev | cut -c 1-8 | rev
"
/usr/sbin/scutil --set ComputerName ${definedComputerName}
/usr/sbin/scutil --set LocalHostName ${definedComputerName}
/usr/sbin/scutil --set HostName ${definedComputerName}
exit 0
Posted on 10-08-2018 07:23 AM
If you are talking about Jamf managed Macs, you could also use the Jamf binary to accomplish this with less hassle:
computerName="populate_this_however_you_want"
jamf setComputerName -name "$computerName"