Saturday, June 6, 2009

Print system information to the console in OS X

All Mac users should know about the System Profiler application in OS X. You may not know it by that name, but you have probably seen it. If you click on the apple in the top left corner of the screen and select the "About This Mac" option a window will appear in the middle of the screen with some basic information about the system. Clicking the "More Info..." button will open the System Profiler app. This handy application hold all sorts of useful information about the system. It lives at /Applications/Utilities/System

There is also a command line version of this application called system_profiler. If you run this program without any arguments it will print all of the system's configuration information, separated into logical groupings. Syntax looks like this:
You can specify how much detail you want like this:
system_profiler -detailLevel [mini/basic/full]
Running this tool without any arguments will provide the standard level of detail for the output. Specifying the detail level will alter this. The "mini" setting will exclude personal information. The "basic" level will only print basic hardware and network information. The "full" level will print everything. This is a lot. On my MacBook Pro the output from the "full" detail level was over 24,000 lines. The standard output was only 830 lines.

You can also specify which categories to print the information about. For example, if you are only looking for information about serial ATA devices you can designate to only print the information for that category. To print a list of available categories use this syntax:
system_profiler -listDataTypes
Once you know what the relevant data types are called, you can specify that like this:
system_profiler [type1] [type2] [...]
So what use is this? The other day I wrote a script using this tool to quickly collect desired information about a group of Macs. One of the pieces of information I wanted to collect was the serial number. To do so you would use this syntax:
system_profiler | grep -m 1 "Serial Number:" | cut -d: -f2- > ~/Desktop/serialNo.txt

No comments:

Post a Comment