Getting information from System Report

mhuppert
New Contributor

Is there a way to collect System Report information through Casper? Our MBAs are getting to the age where the batteries are starting to fail and are showing Service Battery under the battery health info. Even when asked to inform me when this issue surfaces, many of our students will ignore my emails. AppleCare on these computers will be ending soon and I want to get new batteries in the ones that need them, without having to touch each computer.

I would like to be able to set up a smart group where the computer will enter if the Service Battery condition is present.

Thanks.

1 ACCEPTED SOLUTION

bpavlov
Honored Contributor

@mhuppert How about this as an extension attribute?

#!/bin/bash

#Determine model
model=`system_profiler SPHardwareDataType | grep "Model Name:" | cut -d ' ' -f 9`

if [ "$model" = "MacBook" ]; then

#Determine battery condition
result=`system_profiler SPPowerDataType | grep "Condition" | cut -d ':' -f 2 | sed -e 's/^[[:space:]]*//'`
    echo "<result>$result</result>"
else
    echo "<result>Not A MacBook</result>"
fi

I don't have a failed battery to test so I honestly don't know what I'd be looking for, but it will spit out the condition of the battery regardless.

I also don't know what this would spit out on iMacs or Mac Pros which do not have built-in batteries you might want to add in some logic to ignore models where the model identifier is as MacPro, iMac, etc.

I'm also assuming that the Model Name for all MacBooks, MacBook Airs, and MacBook Pros which would allow us to grep for "MacBook".

View solution in original post

12 REPLIES 12

stevewood
Honored Contributor II
Honored Contributor II

@mhuppert there is an Extension Attribute template that will pull Battery Health Status. Just create a new EA, click the "New from Template" button, and find the Battery entries.

Once you have that, you can scope an Smart Group to that EA and set it to email on change of the group.

Jeff-JAMF
New Contributor

There are several Extension Attribute templates that you can use to collect and report battery info e.g. Battery Cycle Count.

You can also look at "Determining battery cycle count for Mac notebooks" for more info on that.
https://support.apple.com/en-us/HT201585

cad93de12878490f94c7d02e3ada4a17

mm2270
Legendary Contributor III

Hi. I suggest going into your JSS under Computer Management > Management Framework > Extension Attributes. Choose "New From Template" and scroll down to the System Information section. There are 9 template EAs you can add for all kinds of battery monitoring. Examples:

  • Battery Charge Percentage
  • Battery Charging
  • Battery Cycle Count
  • Battery Fully Charged
  • Battery Health Status
  • Battery Installed
  • Battery Manufacturer
  • Battery Serial Number
  • Battery Time Remaining

I'm sure one of those, or several, will help out. The one that I think you're looking for is the "Battery Health Status"

Edit: What everyone else said before me!

mhuppert
New Contributor

Thank you for all of your responses.

I got the group set up for the extension attribute of Battery Health Status. the problem is that the template script will look for a specific item value of 1 or 0. 1 will return a "Failure" and a 0 will return an "OK". All of the computers are coming back as OK. That means that "Service Battery" does not mean "Failed Battery" (to the system). In other words, we are close but no cigar.

Any other ideas on how to glean this information from the computers through JSS?

BTW, a Google search was not productive in finding any additional information.

Thanks again.

mhuppert
New Contributor

If it makes a difference, I forgot to mention that these computers are running OS 10.9.5.

Thanks.

bpavlov
Honored Contributor

@mhuppert How about this as an extension attribute?

#!/bin/bash

#Determine model
model=`system_profiler SPHardwareDataType | grep "Model Name:" | cut -d ' ' -f 9`

if [ "$model" = "MacBook" ]; then

#Determine battery condition
result=`system_profiler SPPowerDataType | grep "Condition" | cut -d ':' -f 2 | sed -e 's/^[[:space:]]*//'`
    echo "<result>$result</result>"
else
    echo "<result>Not A MacBook</result>"
fi

I don't have a failed battery to test so I honestly don't know what I'd be looking for, but it will spit out the condition of the battery regardless.

I also don't know what this would spit out on iMacs or Mac Pros which do not have built-in batteries you might want to add in some logic to ignore models where the model identifier is as MacPro, iMac, etc.

I'm also assuming that the Model Name for all MacBooks, MacBook Airs, and MacBook Pros which would allow us to grep for "MacBook".

mm2270
Legendary Contributor III

Just an FYI, its a bit faster to get the model name of the Mac from either ioreg or sysctl, rather than using system_profiler. I tend to only use system_profiler in scripts when there is no other choice, just because its a little sluggish. In the case of sysctl, its also easier in addition to being faster.

## Using ioreg
$ ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/model/{print $4}'
$ MacBookPro11,1
## Using sysctl
$ sysctl hw.model | awk '{print $NF}'
$ MacBookPro11,1

You can then use that with a 'like' comparison in the script, as in:

if [[ "$model" =~ "Book" ]]; then

since all Mac laptops have the word "Book" in them, whereas desktop models do not.

mhuppert
New Contributor

Thanks bpavlov, that script worked!

jhbush
Valued Contributor II

I just wanted to post these here to follow up on @mm2270 suggestion.

#!/bin/bash

#Determine model
model=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/model/{print $4}')

if [[ "$model" =~ "Book" ]]; then

#Determine Battery Cycle Count
result=$(ioreg -r -c "AppleSmartBattery" | grep -w "CycleCount" | awk '{print $3}' | sed s/"//g)
    echo "<result>$result</result>"
else
    echo "<result>Not A MacBook</result>"
fi
#!/bin/bash

#Determine model
model=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/model/{print $4}')

if [[ "$model" =~ "Book" ]]; then

#Determine Battery Serial Number
result=$(ioreg -r -c "AppleSmartBattery" | grep "BatterySerialNumber" | awk '{print $3}' | sed s/"//g)
    echo "<result>$result</result>"
else
    echo "<result>Not A MacBook</result>"
fi

davidi4
Contributor

This may be a Catalina thing, or a MacPro 16" thing, but parsing the Cycle Count using ioreg now includes the next line of info, which I don't want. Suggestions on stripping out the cruft?

# Display battery cycle count
runCommand=$( /usr/sbin/ioreg -r -c "AppleSmartBattery" | /usr/bin/grep -w "CycleCount" | /usr/bin/awk '{print $3}' | /usr/bin/sed s/"//g )
batteryCycleCount="Battery Cycle Count: $runCommand"

Results:

3
{StateOfCharge=97,PMUConfigured=0,Voltage=12691,QmaxCell1=9323,AdapterPower=1107761963,SystemPower=1108040831,ResScale=244,QmaxCell2=9352,QmaxCell0=9325,CycleCount=3,DesignCapacity=8790}

davidi4
Contributor

Never mind, my Google-Fu finally kicked in...

This command gives me just what I want, the numerical value only:

system_profiler SPPowerDataType | grep "Cycle Count" | awk '{print $3}'

mschroder
Valued Contributor

There are now a second line that matches '-w "CycleCount"', that is why you get the CycleCount value (3 in your case) twice.

I think what you are looking for is just the 'BatteryData', so using '-w BatteryData' in the grep (or drop the grep and use "/usr/bin/awk '/BatteryData/ {print $3}'" would be to your liking.