Way to 'get' system properties via terminal.

ziess

Registered
Hi guys,
I'm writing a dashboard widget for MacOSX.com and as part of it I need to be able to get the properties of the system the widget's running on via a terminal command and the paste the result back into the message to be sent.
Getting the widget to make the call to terminal isn't the hard thing and i've pretty much figured out how to combine the result with the message but, as a Unix know-nothing, I don't know any suitable commands to use to find out what I want!
I would like to be able to determine clock speed and possibly type of processor, ideally the type of computer (ie. iMac or Powermac etc), hard drive space, system version and the amount of RAM present.
The idea is to integrate the widget with the tech support side of this site so as to make it easier for people to get support without having to worry about finding figures that they might not understand.

Any help is greatly appreciated.

Tommy
 
You can also try sysctl ( sysctl -a ) for some hardware things like cputype and tools like df for diskspace. That's a lot faster than Apples system_profiler. System version can easily be read with sw_vers

Some examples might be:

sysctl hw.cputype
sysctl hw.cpusubtype
sysctl hw.cpufrequency

If you go through the sysctl -a list you can saa all those values.
And df might be more usefull for you with human readable output: df -h
Just get the values you like out there with grep/awk.

sw_vers can be used to get just the value you want with for example: sw_vers -buildVersion or sw_vers -productVersion

And that's just my personal option: Don't use Apples tools if there is much better/faster 'original' *nix version. ;)

To show just one (ugly) version that multiplies cpu count with clock speed and convert it to MHZ or GHZ you can use:

DUMMY=$(echo "$(sysctl hw.cpufrequency | awk {'print $2'})*$(sysctl hw.activecpu | awk {'print $2'})/1000000" | bc -l | sed 's/\./ /g' | awk {'print $1'}); echo $DUMMY | wc -c | grep [56] > /dev/null && echo "$(echo "$DUMMY/1000" | bc -l | sed 's/\./ /g' | awk {'print $1'}) GHZ" || echo "$DUMMY MHZ"

Just copy/paste this in one piece in the Terminal. It's not a 'good' solution but it's working ;)
 
The last post does work and I agree it usually is best to use as much unix as there is around.

On macOSX I use "system_profiler -detailLevel -2" and egrep out what I want. i.e.

echo `system_profiler -detailLevel -2 | egrep "CPU Speed|Memory|Bus"`

egrep allows you to put more than one argrument, egrep is ubiquitous under UNIX. You don't have to use egrep of course

IRIX, AIX, Solrais, Linux etc have their own plumbing to get at System information and all different.

There used to be a program, which you now have to pay for, call "sysinfo" which can be compiled on all platforms giving a consistent single way to get system info. However its not in UNIX by default and as such not much use.
 
I think i'm going to use system_profiler and egrep out what I need.
So far i'm using 'system_profiler -detailLevel -2 | egrep "CPU Speed|Type|Bus|Memory|Machine|HD|Type|Number Of CPUs|System Version|Kernel Version"' and it's working nicely.

Only thing is that i'm unsure of how to get the hard drive space and PCI/AGP cards installed. I've tried putting additional arguments in via egrep and have mucked about with the detail level to no avail.

Anyone?

Unix is too complicated!
 
UNIX is complicated, or rather more correctly just very flexible and like most profesional applications are hard at first because there's just so much of it. However if you struggle on through a bit further, you'll find out that a lot of what you use is re-usable in a host of other tasks.

For disk space you can use "df -h -l" which gives you the local disk space in human readable format, along with other stats.


Not too sure off hand how to get at easy info on installed cards, I'd have to go and look.

One place you can try is to type "apropos disk".

The word "disk" can be replaced with any arbitraty word of your choice.

It will print a list of commands that are related to your subject.
 
Back
Top