Set Computer Name failing

stilden1978
New Contributor

Good morning everyone!

Was looking for some help.   We are currently running the script below to set our computer names after our new users enroll in JAMF after pre-stage enrollment.

 

#!/bin/bash

#variables
jamfURL="https://xxxxxx.jamfcloud.com"
jamfUser="jamf.api"
jamfPassString="xxxxxxx"
apisalt="xxxxxxx"
apipassphrase="$4"
UDID=$(system_profiler SPHardwareDataType | awk '/Hardware UUID:/{ print $3 }') #gets the UDID of the current machine
serial=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}') #gets the serial number

#decrypt the api password string
function DecryptString() {
	# Usage: ~$ DecryptString "Encrypted String" "Salt" "Passphrase"
	echo "${1}" | /usr/bin/openssl enc -aes256 -d -a -A -S "${2}" -k "${3}"
}
#decrypt API user password
apiPass=$( DecryptString "$jamfPassString" "$apisalt" "$apipassphrase" )

#gets the value of computer record from the JSS via the API
location=$( curl -k -s -u $jamfUser:"$apiPass" "$jamfURL/JSSResource/computers/udid/$UDID/subset/Location" -H "accept: application/xml" -X GET )

#getting the first initial and last name from API xml
realName=$(echo "$location" | /usr/bin/awk -F '<realname>|</realname>' '{print $2}')
firstInitial=$(echo "$realName" | awk '{print $1}' | head -c 1)
lastName=$(echo "$realName" | awk '{print $2}')

# Set Hostname using variables created above
echo "Setting computer name to $firstInitial.$lastName-$serial locally..."
jamf setComputerName -name "$firstInitial.$lastName-$serial"

#Update inventory in jamf pro dashboard
jamf recon

 

I redacted any sort of confidential information for our environment. What is happening after this runs is we are getting  .-xxxxxxxxx where the serial number is populating but not the first.intial.lastname is not populating.  The log file shows on an example machine is showing as follows: 

 

Script result: bad decrypt
4303306220:error:06FFF064:digital envelope routines:CRYPTO_internal:bad decrypt:/System/Volumes/Data/SWE/macOS/BuildRoots/2288acc43c/Library/Caches/com.apple.xbs/Sources/libressl/libressl-56.60.2/libressl-2.8/crypto/evp/evp_enc.c:521:
Setting computer name to .-C02FT33TQ05N locally...
SCPreferencesSetLocalHostName() failed: Invalid argument
Retrieving inventory preferences from https://calendly.jamfcloud.com/...
Finding extension attributes...
Locating applications...
Locating software updates...
Locating plugins...
Searching path: /Applications
Locating accounts...
Locating hard drive information...
Searching path: /Library/Internet Plug-Ins
Locating package receipts...
Locating printers...
Gathering application usage information from the JamfDaemon...
Searching path: /System/Applications
Searching path: /Users
Locating hardware information (macOS 11.3.1)...
Submitting data to https://calendly.jamfcloud.com/...
<computer_id>571</computer_id>

 

If anyone could give this a look and give me some advice or an easier script to give us a better result that would be greatly appreciated.  Here is a couple of screenshots of the policy:Set Computer Name 1Set Computer Name 1Set Computer Name 2Set Computer Name 2

1 REPLY 1

mm2270
Legendary Contributor III

The "bad decrypt" up at the top of the log tells me it can't use the salt or passphrase you're passing to the script to decrypt the credentials for the API call. So likely the API call isn't working and therefore not getting any full user name from the Location section of the device.

If you solve that issue, the rest will likely work. If you want to prove out that it's not getting a name from Jamf, you can add a simple echo command like:

echo "Location: $location"

right after the API call. If you only get Location: returned in the log with nothing displaying after it, then the API call isn't working.