JSS not getting updated computer name

wsg
New Contributor III

I wrote a script to rewrite the computer name. We're using Enterprise Connect, and I have a bash script that's deployed (pkg) to /Library/Scripts/ec, and then gets executed to write the computer name to /tmp/ecUser:

#!/bin/bash
echo $1 > /tmp/ecUser
exit 0;

Here's the script that gets executed, per policy:

#!/bin/bash
if [ ! -f /tmp/ecUser ];
then
    jamfUser=$( echo $3 | sed 's/./-/g' )
    /usr/sbin/scutil --set ComputerName $jamfUser
    /usr/sbin/scutil --set LocalHostName $jamfUser
    /usr/sbin/scutil --set HostName $jamfUser
    echo $jamfUser
else 
    ecUser=$( cat /tmp/ecUser | sed 's/./-/g' )
    /usr/sbin/scutil --set ComputerName $ecUser
    /usr/sbin/scutil --set LocalHostName $ecUser
    /usr/sbin/scutil --set HostName $ecUser
    echo $ecUser
fi 
exit 0;

Here is the result from the policy, in this case the username is coming from /tmp/ecUser, which is matt.marshall, rewritten to be matt-marshall:

Executing Policy e Change Computer Name
Running script Change Computer Name...
Script exit code: 0
Script result: matt-marshall
matt-marshall
Checking for patches...
No patch policies were found.
Running Recon...
Retrieving inventory preferences from https://jss.iterable.zone/...
Locating accounts...
Searching path: /Applications
Locating package receipts...
Locating plugins...
Locating printers...
Gathering application usage information...

Now, everything is working as expected, except that JSS doesn't seem to get updated with the new computer name despite it getting the correct name.

Any ideas what's happening?

Note - reset computer name to Jamf Pro record is not checked.

1 ACCEPTED SOLUTION

mscottblake
Valued Contributor

My first instinct would be to add a pause after the rename takes place and before the inventory is collected.

View solution in original post

2 REPLIES 2

mscottblake
Valued Contributor

My first instinct would be to add a pause after the rename takes place and before the inventory is collected.

wsg
New Contributor III

Yup, that was it. Added a sleep 15, fixed the issue. Thank you!