I've been using this script for the last year and it's worked fine, but is now failing with the following error.
We get the username from the computer record in Jamf Pro as well as the model, truncate the model name (so MacBookPro16,1 becomes MacBookPro), then rename the machine username-xxx depending on the hardware.
Script exit code: 0 Script result: awk: can't open file J152fAP
I don't understand where this is coming from / why it's suddenly started happening / how to fix it. My script-fu is poor so I'd appreciate any insight!
#!/bin/sh
jssUser=$4
jssPass=$5
jssHost=$6
serial=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}')
username=$(/usr/bin/curl -H "Accept: text/xml" -sfku "${jssUser}:${jssPass}" "${jssHost}/JSSResource/computers/serialnumber/${serial}/subset/location" | xmllint --format - 2>/dev/null | awk -F'>|<' '/<username>/{print $3}')
model=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/model/{print $4}' model=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/model/{print $4}') | sed 's/[0-9]*//g')
if [ "$username" == "" ]; then
echo "Error: Username field is blank. Running Recon."
jamf recon -endUsername $(stat -f%Su /dev/console)
fi
if [ "$model" == "MacBook," ]; then
scutil --set HostName "$username-mb"
scutil --set LocalHostName "$username-mb"
scutil --set ComputerName "$username-mb"
fi
if [ "$model" == "MacBookAir," ]; then
scutil --set HostName "$username-mba"
scutil --set LocalHostName "$username-mba"
scutil --set ComputerName "$username-mba"
fi
if [ "$model" == "MacBookPro," ]; then
scutil --set HostName "$username-mbp"
scutil --set LocalHostName "$username-mbp"
scutil --set ComputerName "$username-mbp"
fi
if [ "$model" == "iMac," ]; then
scutil --set HostName "$username-mac"
scutil --set LocalHostName "$username-mac"
scutil --set ComputerName "$username-mac"
fi
if [ "$model" == "MacPro," ]; then
scutil --set HostName "$username-mp"
scutil --set LocalHostName "$username-mp"
scutil --set ComputerName "$username-mp"
fi
echo "New computer name is set."
exit 0