views:

1273

answers:

4

Hi,

I would like to discover the machine architecture type of a big number of machines. I have the hostname of each machine. The machines have Debian 4 linux, SunOS 9, SunOS 10 or Apple Darwin. All are unix-like, but with minor differences.

I would like to know: - architecture (x86, x86_64, ia64, sparc, powerpc...) - processor type (intel pentium, pentium pro, pentium II, sparc, powerpc, itanium, athlon, core 2 duo, cytrix, etc...) - number of processors

Beware, I want the "type" of the machine. The stupid approach using 'uname' does not work on Sun and it also returns things like 'i686' when the machine is in fact 'x86_64' but the operating system is 32 bits. /proc/cpuinfo doesn't work neither, and things get even more complicated because some machines dont have a C compiler installed (I'm sure they all have sh, perhaps python or perl, dunno).

Thanks in advance!! :)

+1  A: 

I would suggest you look at the facter component of the Puppet system. From the URL http://reductivelabs.com/projects/facter/.

A cross-platform Ruby library for retrieving facts from operating systems. Supports multiple resolution mechanisms, any of which can be restricted to working only on certain operating systems or environments. Facter is especially useful for retrieving things like operating system names, IP addresses, MAC addresses, and SSH keys.
earino
Very probably ruby isn't installed on the machines :(
Helltone
+2  A: 

You can try the following Perl one-liner:

perl -MConfig -e 'print "$Config{myarchname}\n";'

I know on Mac OS X Leopard with Perl 5.10.0 it prints "i386-darwin". I don't know of a way in Perl to get the actual processor name - your best bet is probably C since it's a fairly limited set of possibilities. You can get at a C compiler's predefined macros from Perl:

perl -MConfig -e 'print join("\n", split(/ /, $Config{cppsymbols})), "\n";'

This will list C macros like __LITTLE_ENDIAN__ and __MACH__ for Mach-O format and __i386__ (on Leopard at least), as well as the useless ones like __GNUC__ and __STDC__. Of course, all of this help assumes you have Perl on all machines. If not, I'm sure other languages have similar facilities to help you.

Chris Lutz
Thanks, I'll try it tomorrow.
Helltone
+1  A: 

Why /proc/cpuinfo doesn't work?

I don't know all of the OSs you mentioned, but I think it give quite detailed information under Linux. At least, with the model of CPU, other informations can be looked up from a data table.

The software can only see what the OS let it to see, so if the OS doesn't provide informations like /proc/cpuinfo, then you'll have no way to know it.

reply to the comments:

I am not saying look for /proc/cpuinfo for all the OS. It's a two steps method: first you find out which OS it is using uname, then look for the OS specific position for the cpu info.

+1Reading /proc/cpuinfo or running dmidecode is the only sure-fire way to determine what processor you are running on. As you noted, uname reports the type of kernel you are running on and gives different results depending on the type of kernel that has been installed.Not sure about osx or sun.
stephen mulcahy
the /proc filesystem is a Linux invention, it does not exist on other UNIXes.
Mike Heinz
Well, it is not a Linux invention, and it exists on other unix flavours, but it normally contains information about processes (hence its name), not random system information. Therefore this is not an answer to the question.
matli
+3  A: 

arch ; uname -a

arch is the standard way to get the name of the CPU instruction set. uname -a gets a bunch of stuff about the OS. uname withouth the a gets the OS name.

Joshua
arch? Didn't knew about it. I'll try.
Helltone