Hello,
I have a script which I run at first user login to the mac. It searches Active Directory and populates JSS based on the results. Everything works fine with the exception of the -realname field. I understand that when sending -realname from the command line that you need to have a after the first name and before the last name. This is due to the way Macs read whitespace. sudo jamf recon -realname Rafe Moody will populate JSS with Rafe. sudo jamf recon -realname Rafe Moody will populate Rafe Moody in JSS.
In my script I am concatenating the first name and last name variables. When I echo the result for my full name, it displays correctly Rafe Moody but when it is passed to JSS, it results in Rafe . The second variable is missing. I have tried every combination I can think of to get the information to pass. I have tried escape characters for the but haven't found the correct combination. I know my bash syntax is not great but I don't know why it is echoing correctly but not passing to JSS correctly. Below is my code. Any assistance would be appreciated. Note: the script below is adopted for local testing. I have $(whoami) replaced with $3 when running the script through Casper and I don't have the "sudo" in the production code. Also, the echo's are there for tracing/testing.
!/bin/bash
JAMFBin="/usr/local/jamf/bin/jamf"
CurrentUserName=$(whoami)
ADUserHomeCity=$(dscl /Active Directory/DOMAIN -read /Users/$CurrentUserName | awk '$1 == "City:" { print $2}')
ADUserFirstName=$(dscl /Active Directory/DOMAIN -read /Users/$CurrentUserName | awk '$1 == "FirstName:" { print $2}')
echo $ADUserFirstName
ADUserLastName=$(dscl /Active Directory/DOMAIN -read /Users/$CurrentUserName | awk '$1 == "LastName:" { print $2}')
echo $ADUserLastName
ADUserRealName="$ADUserFirstName $ADUserLastName"
echo $ADUserRealName
ADUserEMailAddress=$(dscl /Active Directory/DOMAIN -read /Users/$CurrentUserName | awk '$1 == "EMailAddress:" { print $2}')
sudo $JAMFBin recon -building $ADUserHomeCity -endUsername $CurrentUserName -email $ADUserEMailAddress -realname $ADUserRealName