Posted on 10-30-2023 06:24 PM
HI there,
We've been using a script to set the computer name on devices in the format of 'fullname-model'. This script has been working fine up until Sonoma where it breaks by not providing the full name variable. The only script that seems to work at the moment is one that pulls the username instead but this is not ideal for our environment due to some historic devices having usernames completely unrelated to the user.
Is anyone using a script that is able to pull full name from a source that works on Monterey, Ventura and Sonoma in the 'fullName-model' format?
This is what we have now
#!/bin/bash
userName=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
echo $userName
model=$(system_profiler SPHardwareDataType | grep "Model Name:" | sed 's/.*://' | tr -d " \t\n\r")
echo $model
serialNumber=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
echo $serialNumber
name=$userName-$model-$serialNumber
echo $name
scutil --set HostName "${name}"
scutil --set LocalHostName "${name}"
scutil --set ComputerName "${name}"
Solved! Go to Solution.
Posted on 10-31-2023 07:29 AM
After using the "userName" variable, this command will give you the full name of the user:
finger -s $userName | head -2 | tail -n 1 | /usr/bin/awk '{print $2,$3}'
This will result in FirstName LastName. If you want to remove the space between the first name and last name, you need to add a sed command to the end.
finger -s $userName | head -2 | tail -n 1 | /usr/bin/awk '{print $2,$3}' | sed 's/[[:blank:]]//g'
To make this a variable you could write something like:
fullName=$(finger -s $userName | head -2 | tail -n 1 | /usr/bin/awk '{print $2,$3}' | sed 's/[[:blank:]]//g')
echo $fullName
I tested all of this in Sonoma.
Posted on 10-31-2023 06:25 AM
Where in this script are you trying to grab the full name? I only see you getting the short username.
Also, I don't think it's wise to try to pull a full name as part of a computer name. There could be odd characters, spaces and other things in that which could cause some issues when using it as a host name. Just my $0.02 on the issue. I'd use something more computer/device specific for this. Why not just use the model and serial number like you already have and drop the user name?
Posted on 11-02-2023 07:10 AM
The username/fullname are the only identifying variables for the devices. In order for us to confirm a user just based on serial number we would either have to check our Asset Manager or directly navigate into serial numbers to see the local account associated with the devices.
We currently dont have 'User and location' populated since we use Okta I don't think it can be used to generate this data which would've allowed us to make use of S/N in the device name and create an advanced search filter looking at the User and location data. I may be wrong though.
Posted on 11-02-2023 07:23 AM
Posted on 11-02-2023 07:25 AM
Interesting. Up until just now I thought this data was pulled from and LDAP connector like from Google Workspace or Azure. Thanks for this feedback, I'll give it a go.
Posted on 10-31-2023 07:29 AM
After using the "userName" variable, this command will give you the full name of the user:
finger -s $userName | head -2 | tail -n 1 | /usr/bin/awk '{print $2,$3}'
This will result in FirstName LastName. If you want to remove the space between the first name and last name, you need to add a sed command to the end.
finger -s $userName | head -2 | tail -n 1 | /usr/bin/awk '{print $2,$3}' | sed 's/[[:blank:]]//g'
To make this a variable you could write something like:
fullName=$(finger -s $userName | head -2 | tail -n 1 | /usr/bin/awk '{print $2,$3}' | sed 's/[[:blank:]]//g')
echo $fullName
I tested all of this in Sonoma.
Posted on 10-31-2023 01:01 PM
I'm not trying to be rude here but understand; Why would you want a naming scheme like that vs just Serial Number? Seems way more complex than required.
Posted on 10-31-2023 01:53 PM
But complexity is so much more fun! I have actually taught myself a lot by taking on the challenge of solving problems posted in Jamf Nation. Personally, I would not name a Mac using the user's name since that could be a security problem on a public WiFi network. I wouldn't want my name being broadcast to others. That's one reason all of my own Apple devices use Star Trek names. My MacBook Pro has been called "Enterprise" for several years.
Posted on 11-06-2023 11:15 AM
Just since nobody has brought it up:
fullName=$(id -F $username)
Posted on 11-06-2023 12:23 PM
Well that works too! I didn't know that command.