Skip to main content
Question

Asset Tag and Computer name

  • January 21, 2015
  • 5 replies
  • 41 views

Forum|alt.badge.img+5

Hello, I have two problems. They are different but will be related. I have a .csv file that has:
SerialNumber, CPSD-12345
The first issue is that running the set computer name script is adding quotes around the name. i.e. "CPSD-12345" is presented instead of CPSD-12345

The second problem I have is asset tag assignment. because this .csv file is already present locally on the computer. I would like to run a script that would read from this file and remove the CPSD- and only leave the asset tag to be run. I have researched and have come up short. Any direction in this would be so helpful. My grep skills aren't up to par.

5 replies

davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • January 21, 2015

Not sure about the first part. Do you mean it ends up in the JSS with quote marks? If thats the case it might be a quirk with the jamf script, in which case you might need to create your own.

The second problem can be handled with sed. Something like:

sed -i -- 's/CPSD-//g' /usr/local/bin/MBAnames.csv

Forum|alt.badge.img+7
  • Contributor
  • January 22, 2015
-username MacAdmin -password Appleloosa8

I hope that's not a real domain admin account you just posted.


Forum|alt.badge.img+5
  • Author
  • New Contributor
  • January 22, 2015

I will try that out. And no, that is a made up username and password. But I will remove the script with my domain name just for good measure


Forum|alt.badge.img+7
  • Contributor
  • January 23, 2015

Not sure if this would be of any use, I work in a school environment, and we are at times loaded to the brim with work needing to be done. I wrote this script to rely on the NetBIOSName, which our AD controls NetBIOSName after it's been assigned from imaging. It simply reads the name and then uses it to name the computer using scutil.

#!/bin/sh
#Records name to be set for scutil from NetBIOSName
defaults=$(defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName)

#Sets the scutil names, please note the --get sometimes does not report correctly.
#This is due to scutil not reading the information correctly intermittently after changing it. 
#If you are unsure, you can manually run the --get commands accordingly.
scutil --set HostName $defaults
    scutil --get HostName
scutil --set ComputerName $defaults
    scutil --get ComputerName
scutil --set LocalHostName $defaults
    scutil --get LocalHostName

As for our asset tags, this pulls the same NetBIOSName and uses jamf's own asset command to update the information in Casper.

#!/bin/sh

asset=$(defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName)

jamf recon -verbose -assetTag "$asset"

Forum|alt.badge.img+15
  • Contributor
  • January 23, 2015

For our asset field, we use the last 8 characters of the mac's name... We also hide the asset name in var/db...

#!/bin/sh

#1st get computer name#
COMPNAME=`/usr/sbin/scutil --get ComputerName`

#1a-hidecomputername on system#
touch /var/db/assetnumber
echo $COMPNAME > /var/db/assetnumber

#2-grab the last 8 characters#
vasset=${COMPNAME:(-8)}

#3-set the asset in Casper#
jamf recon -skipApps -skipFonts -skipPlugins -assetTag $vasset

This allows us to change a computer's name back if the user changes it by doing a name comparison and placing the variable if they are not equal....