Posted on 11-06-2013 08:58 AM
Hey All,
I did a bit of searching through the forums but I couldn't find exactly what I was looking for. I'm looking for a way via an extension attribute to find machines that either have a SSD or rotational drive. I don't necessarily need specifics, just if it's rotational or SSD.
I know you could do something like, system_profiler | grep "Medium Type" but I was wondering if anybody had expanded on that.
Thanks in advance for any help.
Posted on 11-06-2013 09:33 AM
I would stay away from the system_profiler command, only because it is too intensive for what you need. Like using a sledgehammer to kill a fly. It takes too long to generate the report, and thus your recons will take forever too.
I would look at using diskutil to do this. You can use the info function of diskutil to grab the info of a drive. This would get you the info you need:
diskutil info disk1 | grep "Media Name"
The caveat to that is that you are assuming disk1 is the only drive in the system and that is your main drive, which in my system is true. However, in a system that is encrypted with FileVault, disk0 is the drive that holds the info about media type, and disk1 does not have that info.
You could make an assumption (not a good idea), and look at disk0 and disk1 info and use either an if/then or case statement or something like that to cycle through the responses. Something like this might work (thrown together so please test):
#!/bin/sh
disk0=`diskutil info disk0 | grep "Media Name" | awk '{ print $6 }'`
disk1=`diskutil info disk1 | grep "Media Name" | awk '{ print $6 }'`
if [[ $disk0 == "SSD" ]]; then
echo "<result>disk0 is SSD</result>"
exit 0
elif [[ $disk1 == "SSD" ]]; then
echo "<result>disk1 is SSD</result>"
exit 0
fi
echo "<result>No SSD Drives</result>"
exit 0
In my mind, however, you'd want to devise a way to list the drives that are installed, and then cycle through those. Could do this with an ls of the /dev folder and grab only diskx items. I'm sure there's a better way, that's just me spit balling off the top of my head.
HTH, and if it doesn't make sense, just ask away.
Posted on 11-06-2013 09:41 AM
Agree with Steve that diskutil is probably a better solution, but if you do use system_profiler you should be sure to specify ```
system_profiler SPStorageDataType
``` - save a lot of extra time and wasted effort.
Posted on 11-06-2013 09:46 AM
Building off of what Steve said, you could use the following if you just want to see if it is a SSD or not.
#!/bin/sh
disk0=`diskutil info disk0 | grep "Solid State" | awk '{ print $3 }'`
disk1=`diskutil info disk1 | grep "Solid State" | awk '{ print $3 }'`
if [[ $disk0 == "Yes" ]]; then
echo "<result>disk0 is SSD</result>"
exit 0
elif [[ $disk1 == "Yes" ]]; then
echo "<result>disk1 is SSD</result>"
exit 0
fi
echo "<result>No SSD Drives</result>"
exit 0
Posted on 11-06-2013 09:51 AM
diskutil info /
will pull information on the boot volume, regardless of whether FileVault 2 encryption is on (meaning there is a CoreStorage volume) or not.
So using that, we can do something like:
#!/bin/sh
MediaType=$(diskutil info / | awk '/Media Type/{print $NF}')
echo "<result>$MediaType</result>"
On my 13" MBP that pulls: "Generic" (whatever that means). I haven't tested the above beyond my own Mac, but I assume on a MBA or other Mac with an SSD, it would report as "SSD" or something along those lines.
Posted on 11-06-2013 10:10 AM
Sorry - should have specified one more key fact. We have been replacing standard rotational Apple drives with 3rd party SSDs. This causes issues with @stevewood's original script. @dcpeterson's modification seems to do the trick (will do a bit more testing and report back). Thanks everyone!
Posted on 11-06-2013 11:13 AM
Actually @mm2270, that won't pull the drive info. That pulls the partition info. So when I run that on my MBA with an SSD in it, Media Type is also Generic for me, and there is no mention of what type of hard drive is in the system.
@dcpeterson great catch on the Solid State flag. I missed that when I did my first pass at that.
Posted on 11-06-2013 11:33 AM
Ah, yes, I see now. My mistake. I think I was looking at some other lines in the output.
In that case, what @dcpeterson][/url][/url wrote up is going to be the best bet. 'Solid State' will tell the tale.
Posted on 11-07-2013 11:35 AM
Hey Everyone,
I do not have an SSD drive, but I think we could build an array of device nodes by doing this:
$ diskutil list | awk '/dev/ { print $1 }'
/dev/disk0
/dev/disk1
Using awk to print out the first column of the output of `diskutil list` command, we can pattern match anything with the word 'dev' in it. This gives me the following output I posted above this.
Now I do not have a SSD to test this, but I just whipped this up together based on what this thread has given me:
#!/bin/bash
# create array of device nodes of mounted volumes
diskList=$(diskutil list | awk '/dev/ { print $1 }')
for i in ${diskList[@]} ; do
echo "<result>$(diskutil info $i | awk '/Media Type/ { print $NF }')</result>"
done
exit 0
Here is the output of my script:
$ bash -x ssd_check.sh
++ diskutil list
++ awk '/dev/ { print $1 }'
+ diskList='/dev/disk0
/dev/disk1'
+ for i in '${diskList[@]}'
++ diskutil info /dev/disk0
++ awk '/Media Type/ { print $NF }'
+ echo '<result>Generic</result>'
<result>Generic</result>
+ for i in '${diskList[@]}'
++ diskutil info /dev/disk1
++ awk '/Media Type/ { print $NF }'
+ echo '<result>Generic</result>'
<result>Generic</result>
Please test and modify if need be to ensure it detects SSD and repost here. If it puts Solid State in the output you can then run advanced reports or create smart groups based on any Mac that has the output "Solid State," in that extension attribute in Casper.
Thanks,
Tom
Posted on 11-07-2013 11:59 AM
I didn't reply back to this again yesterday, but I seriously don't think its necessary to know the disk identifier, since we're talking about an Extension Attribute, which can only run while the Mac is booted from the internal boot volume. Different story if we needed to do this while in an imaging workflow.
The line:
diskutil info / | awk '/Solid State/{print $NF}'
returns a "Yes" or "No". The / identifier returns the same results as using something like "disk1", etc because its all coming from the same boot volume. I don't think there's any need to try to figure out the specific volume identifier.
Posted on 11-07-2013 12:11 PM
Mike,
I agree with you that will most likely work. However, I know some people who have two drives in their Mac laptop, as they have opted to remove their optical drive. Some configurations are a combo of SSD/nonSSD drives. Also, in the older Mac Pros, you could have multiple drives. The end user could be booted off of any drive. I only wrote my code to try to encompass all the possibilities of different models and different configurations. I also know people that often boot to thunderbolt drives, or have a Mac Mini that is connected to a hardware TB array of disks.
My method just detects the model type, then you would sort out smart groups or advanced searches based on the output of that. Furthermore it would allow you to easily and quickly compare how many platter hard drives versus how many solid state hard drives you have in your entire deployment.
Personally, I think this should be a feature request, and just automatically collected and easily reportable in the device record of each Mac in the JSS. I would suggest someone post that in our Feature Request section. I think running a script is a bit of an overkill for this.
Thanks,
Tom
Posted on 11-07-2013 12:25 PM
OK, I can see how a more complicated setup of a Mac Pro with multiple drives, perhaps more than one with a bootable OS on them could get tricky. Fair enough.
I would agree that the drive type should be captured natively in the Casper Suite since almost all other data about any drives installed or attached are captured. Even stuff like the serial number and Revision, so why not the drive type (SSD vs spinning platter) Definitely should be a native item captured.
Posted on 11-07-2013 01:06 PM
I went ahead an added it as an internal feature request in our system. If any of you feel that this is something you would like to see, please post it on JAMF Nation and vote it up.
Thanks,
Tom
Posted on 01-23-2015 12:17 PM
Tell me what I'm doing wrong here…
If I run this script on a Mac, I get a correct response–yes or no–if a solid state drive is present or not. It works.
#!/bin/sh
SSD=diskutil info / | awk '/Solid State/{print $NF}'
if [ $SSD == "Yes" ];then
echo "Yes"
else
echo "No"
fi
exit 0
If I paste this in an extension attribute trying to get a result, nothing is returned when I recon a system.
I know I am overlooking something super-simple (and probably dumb) here. What?
Posted on 01-23-2015 12:29 PM
@Kevin- you forgot to add the <result></result> tags around the echo lines. That's why its not returning anything.
Posted on 01-23-2015 12:49 PM
DOH…Told ya!
Thank you!
Posted on 02-27-2015 06:07 AM
Sorry for jumping into this thread late, we actually have a need to show computers that have SSD boot drives.
Any of our Macs that have SSD would have Apple branded, not third party.
It looks like JSS gathers Storage > Model info, which shows SSD if exists.
The JSS database already has the info we need, I'll open a ticket with JAMF to see if they have a way to display that info in a report/search.
Don
Posted on 03-01-2016 12:48 PM
@donmontalvo Don did you ever get a response from Jamf on this?
I would love access to that info as well.
Gabe Shackney
Princeton Public Schools
Posted on 03-01-2016 12:51 PM
Won't help you now, but you should vote this up and make a comment on gathering this information as well (assuming it's not already in the DB):
https://jamfnation.jamfsoftware.com/featureRequest.html?id=2837
Posted on 03-01-2016 01:19 PM
@gshackney I actually didn't get a chance, other stuff came up.
Posted on 04-21-2017 06:27 AM
I'm working to implement this and created an Extension Attribute with Data Type String and Input Type Script
The full Script is
SSD=diskutil info / | awk '/Solid State/{print $NF}'
if [ $SSD == "Yes" ];then echo "<result>Yes</result>"
else echo "<result>No</result>"
fi
exit 0
I see the Attribute Extension in Hardware reporting, but no values are being populated. Anyone know what I'm doing wrong?
Posted on 04-21-2017 06:31 AM
Have the machines you're looking at done an update inventory since the EA went live? The JSS won't have the info for a machine until that machine has had an inventory update.
Posted on 04-24-2017 02:45 PM
I've tested Saucio's EA and I've forced my machine to report to the JSS and the JSS doesn't show any info in the field.
Ideas?
Posted on 04-24-2017 09:13 PM
@boanes If you copied and pasted saucio's script as it appears above, I can assure you it won't work since it's not a valid script as it's shown. It likely was valid, originally, but the forum will mess up script formatting if it's not wrapped in the script tags to retain the format.
Try the following, which is essentially the same script, but with formatting intact.
#!/bin/sh
SSD=$(diskutil info / | awk '/Solid State/{print $NF}')
if [ $SSD == "Yes" ]; then
echo "<result>Yes</result>"
else
echo "<result>No</result>"
fi
exit 0
Tested against my MBPr and it correctly shows a Yes result since it has an SSD drive as the main boot disk.
Posted on 04-25-2017 07:25 AM
That did it! Thanks @mm2270!
Posted on 04-30-2021 02:46 PM
2021 Update - this script is not working - have confirmed some SSDs were not reported correctly for macOS 10.15
#!/bin/sh
SSD=$(diskutil info / | awk '/SSD/{print $NF}')
if [ $SSD == "Yes" ]; then
echo "<result>Yes</result>"
else
echo "<result>No</result>"
fi
exit 0