Change computer name via scutil and then change it in the JSS

danshaw
Contributor II

I have a script that renames a computer using scutil and I want that new name to be updated in the JSS. I am running this as a policy, but its not updating the JSS name. Do I need to run a recon right away or should the policy do that automatically? What do I need to run in order to have the JSS be updated right away with this new name?

FYI - I realize that I can do this FROM the JSS to the computer, but in this situation I need the computer name to change first and then update the JSS with that new name. Thanks!

7 REPLIES 7

thoule
Valued Contributor II

Recon should update the JSS record. Wait up to 24hrs, or kick off a recon in your script.

strider_knh
Contributor II

If all you did was change the computer name then all it needs to do is check-in and the JSS should update to the new name.

danshaw
Contributor II

Ok thanks guys. So at the end of my script I'll impose a check-in. Just to confirm, all that would be needed is "jamf policy" or a "jamf recon"?

thoule
Valued Contributor II

I just did a quick test which showed 'jamf recon' is required at the end for the JSS to see the new name, yielding a different result than @strider.knh suggests. Of course, you should do your own tests to confirm.

NoahRJ
Contributor II

@danshaw, if you're running this as a policy, you don't need to include the "jamf recon" trigger to force inventory to update. There's a maintenance category under any policy where you can select "Update Inventory", which will run recon after all other tasks have finished.

danshaw
Contributor II

Awesome, thanks @NoahRJ . And thanks for the rest of you who also chimed in. I appreciate the help! I'll give it a try now.

dgreening
Valued Contributor II

I use a version of a cocoadialog enabled script in Self Service to enable local support staff to properly change a computer name and re-bind to AD with the new name. Check it out:

#!/bin/sh
########################################################################
# Created By: Ross Derewianko Ping Identity Corporation
# Creation Date: February, 2015 
# Last modified: December 14th, 2015
# Modified for Sapient: December 14th, 2015 - Daniel Greening
# Brief Description: Changes machine hostname
########################################################################

#check for CocoaDialog & if not install it

if [ -d "/Library/Application Support/JAMF/bin/CocoaDialog.app" ]; then
    CoDi="/Library/Application Support/JAMF/bin/CocoaDialog.app/Contents/MacOS/cocoaDialog"
else
    echo "CocoaDialog.app not found installing" 
    jamf policy -event cocoa
    CoDi="/Library/Application Support/JAMF/bin/CocoaDialog.app/Contents/MacOS/cocoaDialog"
fi

########################################################################
# Functions
#######################################################################

#asks for the new hostname & then call in the cleaner!

function cdprompt() {
    hostname=`"$CoDi" standard-inputbox --float --title "Sapient LS Computer Rename Utility" --informative-text "Enter the new computer name using Sapient naming convention:"`

    if [ "$hostname" == "2" ]; then
        echo "user cancelled"
        exit 1
    fi
    cleanhostname
}

#cleans the first two characters out (cocoaDialog adds a 1 
 to the string value which we don't need.)

function cleanhostname() {
    hostname=${hostname:2}
}

#checks for a blank hostname, and if its blank prompt agian 

function checkforblank() {
    while [[ -z $hostname && {$hostname+1} ]]
    do
        cdprompt
    done
}

function sethostname() {
    scutil --set HostName $hostname
    scutil --set ComputerName $hostname
    scutil --set LocalHostName $hostname
}

########################################################################
# Script
########################################################################

cdprompt
checkforblank
sethostname
jamf policy -event ADBind

The ADBind policy has an "Update Inventory" on it, so I didn't include it in the script.