- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-05-2022 04:09 PM
So the below script was working fine and now no longer wants too. What am i missing?
#!/bin/bash
CurrentUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')
SerialNumber=$(system_profiler SPHardwareDataType | grep "Serial Number" | awk -F':' '{print $2}' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
### Set the computer name using the jamf binary
/usr/local/bin/jamf setComputerName -target / -name "$CurrentUser"-"$SerialNumber"
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-06-2022 10:25 AM
okay, think i got it working.
#!/bin/bash
userName=$(/bin/ls -la /dev/console | /usr/bin/cut -d " " -f 4)
SerialNumber=$(system_profiler SPHardwareDataType | grep "Serial Number" | awk -F':' '{print $2}' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
computerName="$userName-$SerialNumber"
# Set the ComputerName, HostName and LocalHostName
/usr/sbin/scutil --set ComputerName "$computerName"
/usr/sbin/scutil --set HostName "$computerName"
/usr/sbin/scutil --set LocalHostName "$computerName"
exit 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-05-2022 04:14 PM
@GrahamJ I'm going to guess you are on macOS 12.3. python was removed in macOS 12.3. https://www.macrumors.com/2022/01/28/apple-removing-python-2-in-macos-12-3/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-05-2022 05:26 PM
neat miss on my part
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-06-2022 06:56 AM
Recommend changing your script to use this command to get the Current User:
currentUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-06-2022 09:54 AM
Still missing something. Still kicking an -name error.
#!/bin/bash
currentUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
SerialNumber=$(system_profiler SPHardwareDataType | grep "Serial Number" | awk -F':' '{print $2}' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
### Set the computer name using the jamf binary
/usr/local/bin/jamf setComputerName -target / -name "$CurrentUser"-"$SerialNumber"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-06-2022 10:25 AM
okay, think i got it working.
#!/bin/bash
userName=$(/bin/ls -la /dev/console | /usr/bin/cut -d " " -f 4)
SerialNumber=$(system_profiler SPHardwareDataType | grep "Serial Number" | awk -F':' '{print $2}' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
computerName="$userName-$SerialNumber"
# Set the ComputerName, HostName and LocalHostName
/usr/sbin/scutil --set ComputerName "$computerName"
/usr/sbin/scutil --set HostName "$computerName"
/usr/sbin/scutil --set LocalHostName "$computerName"
exit 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-06-2022 11:05 AM
Just remember that device names are broadcast in the clear on any associated network, so it is generally advisable to avoid PII in the device name if at all possible. If all of your users are adults, it may not be an issue, but would be a HUGE red flag in K12 due to the privacy and safety concerns. Just my $0.02.