Posted on 01-12-2022 02:39 PM
The prefix is showing up on the device, but it's not pulling down the serial. I've even tried a few commands I've seen on these forums, and it still won't grab the serial. I am learning scripting, and only know basic commands. I took over for the previous sys admin who left, and he could never get the script to work either.
MODEL=$(sysctl hw.model)
if [[ $MODEL == *"Book"* ]]
then
PREFIX="TRML-"
else
PREFIX="TRM-"
fi
SERIAL=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $7}')
COMPUTERNAME="${PREFIX}${SERIAL}"
/usr/sbin/scutil --set ComputerName $COMPUTERNAME
/usr/sbin/scutil --set LocalHostName $COMPUTERNAME
/usr/sbin/scutil --set HostName $COMPUTERNAME
Solved! Go to Solution.
Posted on 01-12-2022 09:24 PM
ioreg in your script does not seem to be working. Change it as below. You can use system_profile command as well. Add update inventory in the policy to report back the new name.
ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}'
Posted on 01-12-2022 03:01 PM
Here's a couple alternatives to the ioreg command to get the serial number if you wanted to try them in its place:
system_profiler SPHardwareDataType | grep "Serial Number (system)" | awk '{ print $4 }'
or
system_profiler SPHardwareDataType | awk '/Serial/ {print $4}'
Posted on 01-12-2022 03:21 PM
I would suggest adding a sleep 1 between your scutil commands. Otherwise you may see that your name change didn't fully work.
/usr/sbin/scutil --set ComputerName $COMPUTERNAME
sleep 1
/usr/sbin/scutil --set LocalHostName $COMPUTERNAME
sleep 1
/usr/sbin/scutil --set HostName $COMPUTERNAME
sleep 1
Posted on 01-13-2022 07:36 AM
I got it working with a different ioreg command, but went ahead and added sleep between each command to avoid any possible issues. Thank you for the tip.
Posted on 01-12-2022 05:58 PM
I think you need the command jamf recon for uploading the new computer name to Jamf Pro. Otherwise the computer name will be changed back after next check in.
01-13-2022 06:53 AM - edited 01-13-2022 06:54 AM
or use:
jamf setComputerName -name $COMPUTERNAME
Posted on 01-12-2022 09:24 PM
ioreg in your script does not seem to be working. Change it as below. You can use system_profile command as well. Add update inventory in the policy to report back the new name.
ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}'
Posted on 01-13-2022 07:35 AM
this fixed it. Thank you so much!!!!
Posted on 01-13-2022 06:53 AM
As @karthikeyan_mac mentioned, you have the wrong column being printed in the awk section with your original command. Change it to print $4 like noted above and it should pull the serial number. The other alternative ways to grab the serial mentioned by others here should also work.
Posted on 01-19-2022 06:50 AM
The jamf binary can do this for you without even performing a lookup. "/usr/local/jamf/bin/jamf setComputerName -useSerialNumber"