Greetings! I have this script that uses the API to pull the username that's assigned to the computer in the JSS and then name the computer with it.
#!/bin/sh
jssUser=$4
jssPass=$5
jssHost=$6
serial=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
response=$(curl -k -s ${jssHost}/JSSResource/computers/serialnumber/${serial}/subset/location --user ${jssUser}:${jssPass})
real_name=$(echo $response | /usr/bin/awk -F'<username>|</username>' '{print $2}' | cut -c1-11);
if [ "$real_name" == "" ]; then
echo "Error: Username field is blank."
exit 1
else
/usr/sbin/scutil --set HostName "$real_name"
/usr/sbin/scutil --set LocalHostName "$real_name"
/usr/sbin/scutil --set ComputerName "$real_name"
fi
I think the problem is with:
real_name=$(echo $response | /usr/bin/awk -F'<username>|</username>' '{print $2}' | cut -c1-11);
...but I'm not sure what needs to be fixed in order to get it to print the just username again.
Thanks!

