Reputation: 9200
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!! :)
Upvotes: 8
Views: 36734
Reputation: 43317
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.
However programmatically speaking, the equivalent to arch
is uname -m
.
Upvotes: 20
Reputation: 280
The use of uname -a
will bring you to much information, so you have to search for the information you want to have.
Just use:
uname -i
for the hardware platform
or
uname -m
for the machine hardware name
Upvotes: 0
Reputation: 462
This is not a complete answer, but it may help you reach your goal.
arch does not work on HP-UX Itanium, and it does not have the /proc filesystem, as you mentioned.
This explains how to determine the endianness (byte order) the O/S is using simply with shell commands. It works on at least 4 major Unixes (Linux x86_64, Solaris Sparc, AIX/Power, HP-UX Itanium). If you know the byte ordering you can deduce a lot about which CPU you're dealing with, based on this source.
For instance, if Solaris won't tell you the correct architecture, but you see that it's big endian, you at least know you're not on x86_64, and probably Sparc.
Finally, for Sparc you can do this to determine whether the OS is running in 32 or 64 bit mode:
# isalist -v
sparcv9+vis2 sparcv9+vis sparcv9 sparcv8plus+vis2 sparcv8plus+vis sparcv8plus sparcv8 sparcv8-fsmuld sparcv7 sparc
If it says 'sparcv9' it's 64 bit, sparcv8 is 32
Upvotes: 1
Reputation: 786
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.
Upvotes: 2
Reputation: 697
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.
Upvotes: 4
Reputation: 2945
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.
Upvotes: 2