Posted on 06-12-2019 12:53 AM
I'm running a bash script to update the computer name of our Macs dynamically based on a combination of the current user and our standard PC naming convention. This updates the computer name successfully, I can see this is reflected within systems preferences > sharing, but despite running a recon afterward, the new computer name isn't reflected in the JSS Computer inventory, it still says, for example, Pete's MacBook Pro.
Any ideas on how this field can be updated based on the new actual name of the device?
Posted on 06-12-2019 05:25 AM
Post a copy of your script. We can start there and see if anything obvious needs to be modified in your coding.
Posted on 06-12-2019 05:52 AM
When we set the computer name, our code does a recon to update the JSS, looks like:
# Check name is right
counter=0
livename=`/usr/sbin/scutil --get ComputerName`
until [ $livename == $name ]; do
/usr/sbin/scutil --set LocalHostName "${name}"
/usr/sbin/scutil --set ComputerName "${name}"
/usr/sbin/scutil --set HostName "${name}"
# Set the NetBIOS name
defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "${name}"
sleep 2
livename=`/usr/sbin/scutil --get ComputerName`
if [ "$counter" -gt 4 ]; then
echo "Breaking loop and failing out as we cannot set the computer name"
exit 0;
fi
done
dscacheutil -flushcache
echo "$0: Set machine name to ${name}"
echo "$0: Updating JSS"
/usr/local/bin/jamf recon -endUsername ${uun}
Posted on 06-12-2019 06:59 AM
Script is:
USERNAME=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + " ");')
netnameprefix=$"DA-"
netname=$"$netnameprefix$USERNAME"
sudo scutil --set HostName $netname
sudo scutil --set LocalHostName $netname
exit 0
Even after a jamf recon, nothing updates?
Posted on 06-12-2019 07:40 AM
I've got this working, was missing --setComputerName - it's this bit that the inventory must base itself off?