Does anyone have a script that will name a Mac, and then keep the computer name and host name synced up? We typically name our Macs as app-serialnumber. The "app-" designates that it is an Apple, but the serial number is just that. Any help?
Solved
Script to name Mac, then keep computer name and hostname in sync?

Best answer by ewu-it
Here is a script that should do exactly what you asked. If the computer is not named appropriately it fixes it and updates JAMF to make sure the name is proper. If the name matches it does nothing.
You could use this with OutSet in the boot-every section so that each time the machine is started it would make this check and correct it if necessary.
#!/bin/bash
# Setup Variables
serialNumber=$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F'"' '/IOPlatformSerialNumber/{print $(NF-1)}')
desiredComputerName="app-$serialNumber"
#The next block will check the current computer name and change it if it doesn't match desiredComputerName.
if [ "$desiredComputerName" != "$HOSTNAME" ]; then
/usr/local/jamf/bin/jamf setcomputername -name "$desiredComputerName"
/usr/local/jamf/bin/jamf recon
fi
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.