Skip to main content
Solved

JSS not getting updated computer name

  • February 14, 2018
  • 2 replies
  • 18 views

Forum|alt.badge.img+4
  • Contributor
  • 12 replies

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.

Best answer by mscottblake

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

2 replies

mscottblake
Forum|alt.badge.img+24
  • Honored Contributor
  • 341 replies
  • Answer
  • February 14, 2018

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


Forum|alt.badge.img+4
  • Author
  • Contributor
  • 12 replies
  • February 14, 2018

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