Hello, I would like to change computer host and localhost name to specific values after enrollment.
I need:
computer name to be "name.surname"
localhost name to be "name-surname.local"
host name to be "name-surname"
With this script I managed to change computer to correct value but localhost name is not changing. Can somebody help me finding out where is a mistake please?
#gets current logged in user
getUser=$(ls -l /dev/console | awk '{ print $3 }')
#gets named
firstName=$(finger -s $getUser | head -2 | tail -n 1 | awk '{print tolower($2)}')
lastName=$(finger -s $getUser | head -2 | tail -n 1 | awk '{print tolower($3)}')
computerName=$firstName.$lastName
hostName=$firstName"-"$lastName
#set all the names in all the places
scutil --set ComputerName "$computerName"
scutil --set HostName "$hostName"
scutil --set LocalHostName "$hostName"
sudo jamf recon
Best answer by Kirill11
Kirill11 wrote:
Thank you for this solution but it works not always for some reason. Every second time it changes name to setup.user and setup-user even i created "Jamf Test" user as Full Name on PreStage enrollment
I use this as you recommended
#!/bin/sh
#gets current logged in user
getUser=$(ls -l /dev/console | awk '{ print $3 }')
# Get the Serial Number of the Machine
sn=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
#gets named
firstName=$(finger -s $getUser | head -2 | tail -n 1 | awk '{print tolower($2)}')
lastName=$(finger -s $getUser | head -2 | tail -n 1 | awk '{print tolower($3)}')
computerName=$firstName.$lastName
hostName=$firstName"-"$lastName
#set all the names in all the places
scutil --set ComputerName "$computerName"
sleep 3
scutil --set HostName "$hostName"
sleep 3
scutil --set LocalHostName "$hostName"
sleep 3
/usr/bin/dscacheutil -flushcach
Try slowing things down, add a 'sleep 3' after each scutil commands. I also run the following after all three run. /usr/bin/dscacheutil -flushcache
Thank you for this solution but it works not always for some reason. Every second time it changes name to setup.user and setup-user even i created "Jamf Test" user as Full Name on PreStage enrollment
Thank you for this solution but it works not always for some reason. Every second time it changes name to setup.user and setup-user even i created "Jamf Test" user as Full Name on PreStage enrollment
I use this as you recommended
#!/bin/sh
#gets current logged in user
getUser=$(ls -l /dev/console | awk '{ print $3 }')
# Get the Serial Number of the Machine
sn=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
#gets named
firstName=$(finger -s $getUser | head -2 | tail -n 1 | awk '{print tolower($2)}')
lastName=$(finger -s $getUser | head -2 | tail -n 1 | awk '{print tolower($3)}')
computerName=$firstName.$lastName
hostName=$firstName"-"$lastName
#set all the names in all the places
scutil --set ComputerName "$computerName"
sleep 3
scutil --set HostName "$hostName"
sleep 3
scutil --set LocalHostName "$hostName"
sleep 3
/usr/bin/dscacheutil -flushcach
Thank you for this solution but it works not always for some reason. Every second time it changes name to setup.user and setup-user even i created "Jamf Test" user as Full Name on PreStage enrollment
I'm guessing here but since this appears to be happening at enrollment and sometimes you get the naming you want, I think this is a timing issue. I think the user you are expecting hasn't been created yet or the system hasn't logged in as it yet or something else.
For my DEP machines, which aren't domain joined, I rename them at enrollment complete by their serial number, that way we can actually find them easily in the JSS. Then later, I have a script available in Self Service and at login to prompt to rename the machine. Our techs still "setup" machines for our clients as we haven't moved completely to the out of box experience.
If it is a timing thing, perhaps naming your rename policy to zzz.rename-mac will help you out since zzz will be the last thing to run after enrollment.
Notice below in your screenshot that the "user at login" is mbsetupuser. Might be a clue as to what's going on, might not be! ;)
I'm guessing here but since this appears to be happening at enrollment and sometimes you get the naming you want, I think this is a timing issue. I think the user you are expecting hasn't been created yet or the system hasn't logged in as it yet or something else.
For my DEP machines, which aren't domain joined, I rename them at enrollment complete by their serial number, that way we can actually find them easily in the JSS. Then later, I have a script available in Self Service and at login to prompt to rename the machine. Our techs still "setup" machines for our clients as we haven't moved completely to the out of box experience.
If it is a timing thing, perhaps naming your rename policy to zzz.rename-mac will help you out since zzz will be the last thing to run after enrollment.
Notice below in your screenshot that the "user at login" is mbsetupuser. Might be a clue as to what's going on, might not be! ;)
@ubcoit I think you are right, script runs straight after enrollment completed, but account is not created yet. I changed policy to run after log in and it works :) Than you very much!
Now I have another Issue where the machines are not installing the Jamf Binary so the machines are un-managed only via DEP. If i do them myself, everything works fine.
#!/usr/bin/env bash
# Get the Serial Number of the Machine
sn=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
sn="Lab-C119-Mac-$sn"
# Set the ComputerName, HostName and LocalHostName
scutil --set ComputerName $sn
scutil --set HostName $sn
scutil --set LocalHostName $sn
# Set the computer name in Jamf to reflect what is set locally on the computer
/usr/local/bin/jamf setComputerName -name $sn
/usr/local/bin/jamf recon
echo "Computer name has been changed to $sn"
exit 0
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.