# Shell Script for OS identification on all Platforms

**URL:** <https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473>\
**Category:** Shell Programming and Scripting\
**Created:** [August 31, 2011, 1:54am UTC](https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473 "2011-08-31T01:54:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeevanm](https://community.unix.com/letter_avatar/jeevanm/32/5_5575768a8748004e209b776fc1b2916d.png) [@Jeevanm](https://community.unix.com/u/Jeevanm)\
**Post date:** [August 31, 2011, 1:54am UTC](https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473/1 "2011-08-31T01:54:55Z")

</div>

Hi Mates,

I am writing a Shell script for identifying OS installed on the machine (it can Be any Unix like Solaris, AIX, RHEL, OEL, HP-UX ). With That I want to select appropriate software listed out in a file.

My Question here is, what are the appropriate flags to be used with "uname" command to accurately Identify OS and all necessary parameters like kernal (on all platforms), whoes entries I should maintain in the File along with software name.

I do not want to use "Uname -a"

Awaiting response from all.

Thanks

---

<div class="post-metadata">

**Author:** ![itkamaraj](https://community.unix.com/user_avatar/community.unix.com/itkamaraj/32/1880_2.png) [@itkamaraj](https://community.unix.com/u/itkamaraj)\
**Post date:** [August 31, 2011, 2:20am UTC](https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473/2 "2011-08-31T02:20:36Z")

</div>

look into the file /etc/release

---

<div class="post-metadata">

**Author:** ![yazu](https://community.unix.com/user_avatar/community.unix.com/yazu/32/7048_2.png) [@yazu](https://community.unix.com/u/yazu)\
**Post date:** [August 31, 2011, 2:37am UTC](https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473/3 "2011-08-31T02:37:40Z")

</div>

Hmm... flags. Maybe a [script](http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob_plain;f=build-aux/config.guess;h=4c8f032e786ebd6e6096748030da311c870e751a;hb=HEAD)? 😉

---

<div class="post-metadata">

**Author:** ![Jeevanm](https://community.unix.com/letter_avatar/jeevanm/32/5_5575768a8748004e209b776fc1b2916d.png) [@Jeevanm](https://community.unix.com/u/Jeevanm)\
**Post date:** [August 31, 2011, 2:47am UTC](https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473/4 "2011-08-31T02:47:09Z")

</div>

Hi itkamaraj,

I can't, because

1. its not a common file across all platforms, neither the release files on all platform has common format.
2. I want to have specific information (in a tabular form) in a file.

Example data I want to have in a csv file is something like below. ( I am expecting right columns/uname flags which are valid accross all platforms and can be mentioned appropriately against software verision

```nohighlight
#OS(uname -o),HWP(uname -i),KrnlRelse (uname -r),SOFTWARE_Setup_NAME
GNU/Linux,i386,2.6.18-128.el5,wls1032_linux_i386.jar
GNU/Linux,i386,2.6.18-128.el5,oracle11gr2_linux_32bitx86

```

---

<div class="post-metadata">

**Author:** ![frank\_rizzo](https://community.unix.com/letter_avatar/frank_rizzo/32/5_5575768a8748004e209b776fc1b2916d.png) [@frank\_rizzo](https://community.unix.com/u/frank_rizzo)\
**Post date:** [August 31, 2011, 8:24am UTC](https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473/5 "2011-08-31T08:24:29Z")

</div>

use uname with no arguments

---

<div class="post-metadata">

**Author:** ![pludi](https://community.unix.com/user_avatar/community.unix.com/pludi/32/1278_2.png) [@pludi](https://community.unix.com/u/pludi)\
**Post date:** [August 31, 2011, 8:45am UTC](https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473/6 "2011-08-31T08:45:41Z")

</div>

Or use [man uname (POSIX)](https://www.unix.com/man-pages.php?query=uname&section=0&os=POSIX) with the options specified in the POSIX standard. Those (with 99% certainty) will work on any Unix/-compatible platform.

---

<div class="post-metadata">

**Author:** ![purdym](https://community.unix.com/letter_avatar/purdym/32/5_5575768a8748004e209b776fc1b2916d.png) [@purdym](https://community.unix.com/u/purdym)\
**Post date:** [August 31, 2011, 8:54am UTC](https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473/7 "2011-08-31T08:54:32Z")

</div>

How about starting with

```nohighlight
uname -s

```

?

From there, based on the OS, run OS specific commands to get the information you need.

---

<div class="post-metadata">

**Author:** ![drl](https://community.unix.com/user_avatar/community.unix.com/drl/32/542_2.png) [@drl](https://community.unix.com/u/drl)\
**Post date:** [August 31, 2011, 10:08am UTC](https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473/8 "2011-08-31T10:08:46Z")

</div>

Hi.

> [@yazu](#):
>
> Hmm... flags. Maybe a [script](http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob_plain;f=build-aux/config.guess;h=4c8f032e786ebd6e6096748030da311c870e751a;hb=HEAD)? 😉

+1

The config.guess shell script referred to by yazu is very thorough and can discriminate among an impressive number of systems.

Even if you do not use config.guess directly, you may be able to learn something from how they determine the system, including the use of uname ... cheers, drl

---

<div class="post-metadata">

**Author:** ![Jeevanm](https://community.unix.com/letter_avatar/jeevanm/32/5_5575768a8748004e209b776fc1b2916d.png) [@Jeevanm](https://community.unix.com/u/Jeevanm)\
**Post date:** [September 1, 2011, 5:47am UTC](https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473/9 "2011-09-01T05:47:59Z")

</div>

Hi Purdym,

Yes,I am using the same approach, however I just want to understand what should be used on every specific platform in order to identify the software compatibility.

When we say a software is compatible for 32-bit/x86/i386 etc. what it refers to

is it processor type or hardware platform or hardware name (e.g. Linux Uname flags -p,-i or -m respectively) or its something else.  
If you can clarify this I will be able to look for appropriate flags to be listed.

Thanks

---

<div class="post-metadata">

**Author:** ![fpmurphy](https://community.unix.com/user_avatar/community.unix.com/fpmurphy/32/110_2.png) [@fpmurphy](https://community.unix.com/u/fpmurphy)\
**Post date:** [September 1, 2011, 9:34am UTC](https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473/10 "2011-09-01T09:34:13Z")

</div>

> [@](#):
>
> When we say a software is compatible for 32-bit/x86/i386 etc. what it refers to

At a macro level, it depends on:

- Endianness, i.e. Big or Little
- Data model, i.e. LP16, ILP32, LP64, etc.
- Hardware architecture, i.e. x86, MIPS, SPARC, etc.

---

<div class="post-metadata">

**Author:** ![drl](https://community.unix.com/user_avatar/community.unix.com/drl/32/542_2.png) [@drl](https://community.unix.com/u/drl)\
**Post date:** [September 1, 2011, 10:13am UTC](https://community.unix.com/t/shell-script-for-os-identification-on-all-platforms/294473/11 "2011-09-01T10:13:33Z")

</div>

Hi.

The config.guess produces the signature on an AIX box as:

```nohighlight
$ config.guess 
powerpc-ibm-aix5.1.0.0

```

on an HP box as:

```nohighlight
$ config.guess 
hppa1.1-hp-hpux11.11

```

on a GNU/Debian Linux amd64 machine as:

```nohighlight
% config.guess 
x86_64-unknown-linux-gnu

```

These are copies of the script without modification as run on those machines, simply ftp'd and run.

Best wishes ... cheers, drl
