Skip to main content
Solved

LocalHostName change error


Forum|alt.badge.img+7
Hi, I got some issues with the computer name changes in my environment. Changing the computer names directly after the prestage enrolment and changing the computers based on serial number (HMserial). Everything is correct except for the LocalHostName change. Unfortunately this does not happen for all devices but just for some of them. Script I use: #!/bin/bash #Get Serial number SerialNumber=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}') scutil --set ComputerName "HM-$SerialNumber" scutil --set HostName "HM-$SerialNumber" scutil --set LocalHostName "HM-$SerialNumber" ComputerName and HostName are changing correctly but for the LocalHostName change I receive a failure: SCPreferencesSetLocalHostName() failed: Invalid argument The strange part is that this is not happening for al computers but just for some of them. Anyone has an idea what can be the cause of this error and how to solve it? Help is appreciated!

Best answer by Joostvantwout

Got it working via a workaround script:

#!/bin/bash

 

#Grab current computer name

computername=$(scutil --get ComputerName)

echo "Computername: $computername"

 

#Grab current LocalHostName

LocalHostName=`/usr/sbin/scutil --get LocalHostName`

echo "LocalHostName: $LocalHostName"

 

if [ "$computername" == "$LocalHostName" ]; then

echo "Computername and LocalHostName is a match"

else

echo "Computername and LocalHostName do not match"

echo "$computername" >> /Users/Shared/CorrectHostName.txt

File="/Users/Shared/CorrectHostName.txt"

Hostname=$(cat "$File")

echo "LocalHostname will be changed to: $Hostname"

sudo scutil --set LocalHostName "$HostName"

sleep 3

LocalHostNameChanged=`/usr/sbin/scutil --get LocalHostName`

echo "LocalHostName after change: $LocalHostNameChanged"

rm /Users/Shared/CorrectHostName.txt

fi

 

View original
Did this topic help you find an answer to your question?

3 replies

Forum|alt.badge.img+8
  • Valued Contributor
  • 106 replies
  • December 23, 2022

we have used the following for the last few years. I  do not recall seeing that error. Maybe order matters or the jamf command is masking it in our script,hth

 

scutil --set ComputerName $SerialNumber
scutil --set LocalHostName $SerialNumber
scutil --set HostName $SerialNumber
jamf setComputerName -name $SerialNumber

jamf recon


Forum|alt.badge.img+7
  • Author
  • Contributor
  • 17 replies
  • December 27, 2022

Like I said, there is nothing wrong with the script itself as on half of my Mac's it's changing the names just fine. It's just for a couple of Mac's where we receive the error: SCPreferencesSetLocalHostName() failed: Invalid argument
Manual changing is not an option.


Forum|alt.badge.img+7
  • Author
  • Contributor
  • 17 replies
  • Answer
  • December 28, 2022

Got it working via a workaround script:

#!/bin/bash

 

#Grab current computer name

computername=$(scutil --get ComputerName)

echo "Computername: $computername"

 

#Grab current LocalHostName

LocalHostName=`/usr/sbin/scutil --get LocalHostName`

echo "LocalHostName: $LocalHostName"

 

if [ "$computername" == "$LocalHostName" ]; then

echo "Computername and LocalHostName is a match"

else

echo "Computername and LocalHostName do not match"

echo "$computername" >> /Users/Shared/CorrectHostName.txt

File="/Users/Shared/CorrectHostName.txt"

Hostname=$(cat "$File")

echo "LocalHostname will be changed to: $Hostname"

sudo scutil --set LocalHostName "$HostName"

sleep 3

LocalHostNameChanged=`/usr/sbin/scutil --get LocalHostName`

echo "LocalHostName after change: $LocalHostNameChanged"

rm /Users/Shared/CorrectHostName.txt

fi

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings