Need Ext. Attribute for model name

ooshnoo
Valued Contributor

Our inventory peeps aren't happy with the fact that Casper displays each model name exactly how Apple names it..

Meaning, they don't like "MacBook Pro (Mid 2012)"

They just want it to say "MacBook Pro" or "MacBook Air"

I've got the follwing ext. attribute that sort of does the trick:

#!/bin/sh
Kind=system_profiler SPHardwareDataType | grep "Model Name"
echo "<result>$Kind</result>"

However that returns the result as: Model Name: MacBook Pro And they still don't like that cuz they have to edit out "Model Name"

Does anyone have any idea how to get it to say just "MacBook Pro" ???

Thanks!!!

A

1 ACCEPTED SOLUTION

karthikeyan_mac
Valued Contributor

Try,

#!/bin/sh
Kind=system_profiler SPHardwareDataType | grep "Model Name" | awk '{ print $3" "$4}'
echo "<result>$Kind</result>"

Thanks & Regards,
Karthikeyan M

View solution in original post

5 REPLIES 5

frozenarse
Contributor II

is the first part of the result always going to be "Model Name:"?

karthikeyan_mac
Valued Contributor

Try,

#!/bin/sh
Kind=system_profiler SPHardwareDataType | grep "Model Name" | awk '{ print $3" "$4}'
echo "<result>$Kind</result>"

Thanks & Regards,
Karthikeyan M

tlarkin
Honored Contributor

Hey Everyone,

I did not have a lot of time to test this, so please test, test, test before putting it into production.

bash-3.2$ system_profiler SPHardwareDataType | awk '/Model Identifier:/ { print $3 }' | sed 's/[0,-9]*//g'
MacBookPro

That strips out the numbers and comma.

Thanks,
Tom

ooshnoo
Valued Contributor

Perfect. Thank you Karthikeyan!!!

mm2270
Legendary Contributor III

Though the output isn't as "pretty", there is a somewhat faster way to get this info in an EA. I don't like using 'system_profiler' unless absolutely necessary because its a bit slow. We have so many EA's in our inventory that I'm constantly looking for ways to make the scripts more efficient to reduce inventory time.

You can try this-

#!/bin/sh

Model=`ioreg -c IOPlatformExpertDevice | grep MacBook | awk -F"= " '/model/{ print $2 }' | sed -e 's/^..//;s/..$//;s/[0,-9]*//g'`

echo "<result>$Model</result>"

The results will look like-

MacBookPro
MacBookAir
Macmini
MacPro
iMac

etc, so as I said, not as readable, but still useful.