Skip to main content

Hello to all. I'm using the following naming script to manually rename a computer. I renames the computer fine but it doesn't change the name in JAMF. It still is just listed as "iMac". Any thoughts?



!/bin/bash



sleep 30



RENAME COMPUTER



ComputerName=`/usr/bin/osascript <<EOT
tell application "System Events"
activate
with timeout of 86400 seconds
set ComputerName to text returned of (display dialog "Please Input Computer Name" default answer "" with icon 2)
end timeout
end tell
EOT`



echo $ComputerName
sudo scutil --set HostName $ComputerName
sudo scutil --set LocalHostName $ComputerName
sudo scutil --set ComputerName $ComputerName



echo "Rename Successful"
sudo /usr/local/bin/jamf recon



sleep 10



RUN CASPER POLICIES IN THE FOLLOWING ORDER



sudo jamf policy -event ADBind



sudo jamf policy -event ProgressBarApp



sudo open /Applications/Utilities/ProgressScreen.app



sudo jamf policy -event BaseAppsInstall



sudo jamf policy -event QuitProgressScreen



sudo jamf policy -event ImageSettings



exit -0

First off, you can drop all of the sudo's in your script. Assuming the entire script is being called in a Jamf policy, it's already running as root, so those aren't needed.



Second, in my own computer renaming script, I do the following 3 commands after applying the new name



/usr/bin/killall -HUP mDNSResponder
/usr/bin/killall mDNSResponderHelper
/usr/bin/dscacheutil -flushcache


I then wait about 3 seconds sleep 3, before I collect inventory back to Jamf. I found that the old computer name tends to stick around very annoyingly unless those processes are restarted and the cache is flushed and I give it a few seconds before telling Jamf what the new name is. Now, it's possible doing all 3 above is overkill; maybe only one or two are needed; but I keep all 3 there to be extra sure. It has been working well for me so I'm sticking with it for now.



Give that a try and see if it helps you too.


Reply