Skip to main content
Question

scutil scrpit help

  • October 5, 2018
  • 3 replies
  • 25 views

Forum|alt.badge.img+1

I am really new to scripting, and i was thinking if i can make a script for computer name, Localhostname, and hostname.

i used to just open terminal then

type

sudo scutil --set Computer Name XXX
sudo scutil --set LocalHostName
sudo scutil --set HostName

pleae help me if below script is okay!

thank you

!/bin/sh

!/bin/bash

Enter the Computer name using scutil

setName=scutil --set ComputerName

scutil --set LocalHostName ${setName}
scutil --set HostName ${setName}

echo HostName and LocalHostName set to ${setName}

exit 0

3 replies

Forum|alt.badge.img+18
  • Contributor
  • October 5, 2018

Oh boy. Lots of stuff there will break your script.

First, you need a way for the script to know what name you want. Besides that, the script would look more like this:

#!/bin/sh

scutil --set ComputerName $setName
scutil --set HostName $setName
scutil --set LocalHostName $setName

If you are trying to read in the ComputerName and set that for the other two names, that would look like:

#!/bin/sh

setName=$(scutil --get ComputerName)
scutil --set HostName $setName
scutil --set LocalHostName $setName

Forum|alt.badge.img+1
  • New Contributor
  • October 6, 2018

This is what mines looks like:

!/bin/bash

Simple script that names the computer.

Last 8 characters of the Serial Number:

definedComputerName="/usr/sbin/system_profiler SPHardwareDataType | awk '/Serial Number/ { print $NF }' | rev | cut -c 1-8 | rev"

/usr/sbin/scutil --set ComputerName ${definedComputerName}
/usr/sbin/scutil --set LocalHostName ${definedComputerName}
/usr/sbin/scutil --set HostName ${definedComputerName}

exit 0


Forum|alt.badge.img+19
  • Contributor
  • October 8, 2018

If you are talking about Jamf managed Macs, you could also use the Jamf binary to accomplish this with less hassle:

computerName="populate_this_however_you_want"
jamf setComputerName -name "$computerName"