A script to detect system type


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users A script to detect system type
# 1  
Old 01-24-2018
A script to detect system type

Hi forum,

So I am trying to determine the OS type with the following script:

Code:
#!/usr/bin/sh

OStype1=`uname -s`
Sunos1=SunOs

if [ "${OStype1}" = "Linux" ]
then
  echo "This system is Linux"
   exit 0
elif [ "${OStype1}" = "SunOs" ]
        then
                echo "This system is SunOs"
   exit 0
elif [ "${OStype1}" = "HP-UX" ]
        then
                echo "This system is HP-UX"
   exit 0

   else
   echo "This system is not supported"

 exit 0

fi

So far it is working ok for linux and hp-ux system types, but with no luck on Solaris.

Although the
Code:
OStype1=`uname -s

equals
Code:
SunOs

I still get this system is not supported

Code:
# sh -x test.sh
+ uname -s
OStype1=SunOS
Sunos1=SunOs
+ [ SunOS = Linux ]
+ [ SunOS = SunOs ]
+ [ SunOS = HP-UX ]
+ echo This system is not supported
This system is not supported
+ exit 0


Can you help me out by suggesting how to fix the script in order to work for Solaris?

---------- Post updated at 04:45 AM ---------- Previous update was at 04:29 AM ----------

Sorry to bother you, I have typed SunOs instead of SunOS. It is ok now.
# 2  
Old 01-24-2018
Might I also suggest a case statement rather that if...then...elif...then...elif...then...elif...then...fi

Perhaps this might be neater:-
Code:
case "${OSType1}" in
   Linux)      echo "This is Linux"     ;;
   SunOS)      echo "This is Solaris"   ;;
   HP-UX)      echo "This is HPUX"      ;;
   AIX)        echo "This is the best." ;;
   *)          echo "This in unknown"   ;;
esac

You can add more statements between each choice. The last statement to be run for each choice ends in ;; and esac ends the whole case statement.



I hope that this helps,
Robin
This User Gave Thanks to rbatte1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Detect Operating System

Hi, I need a script that needs to detect the Operating System and based upon wheter it is Linux, Solaris x86, Sparc, Itanium etc it should populate "ps" command with detailed output accordingly for example: ps -xef | grep java -> Itaniumps -auxwww | greap java -> Solaris (9 Replies)
Discussion started by: mohtashims
9 Replies

2. AIX

AIX 5.2 installation on 'IBM system p5 type 9110-51A'

Hi All, I am new to AIX, not completly though.. I got a task to install AIX 5.2 on 'IBM system p5 type 9110-51A' server. I tried few things, but i am not able to get to the console of this server to proceed with the installation. I have installed AIX 6.1 earlier, but those servers can be plugged... (4 Replies)
Discussion started by: nd007
4 Replies

3. HP-UX

How to determine the fie system type?

Good day I need create new mount points on a server. I'm not very familiar with HP-UX and was given steps on how to go about doing the mounting, etc. Before I start though, I need to determine which file system type is currently being used. This will determine whether i need to extend the... (3 Replies)
Discussion started by: notreallyhere
3 Replies

4. UNIX for Advanced & Expert Users

how to findout the file system type?

Hi all, How to findout the file sytem type which is NFS and which is Local? Suppose i have 5 different folders my in Root directory. dir 4 and 5 are mounted on different file system and dir 1,2 and 3 are mounted on different fild system Now i wanted know which file sytem is Local and which... (1 Reply)
Discussion started by: psiva_arul
1 Replies

5. Red Hat

File system type

Hi all, How to find out what type of file system is my system configured for Red hat linux 8.0 ? whether it is NTFS or FAT32 or FAT16... Can somebody help me on this? Regards, William (4 Replies)
Discussion started by: William1482
4 Replies

6. UNIX for Dummies Questions & Answers

How do I know what type of shells are available in my Unix system?

How do I know what type of shells are available in my Unix system? Are there a single command or environment variable that can let me find that out? Best regards, John Chan (7 Replies)
Discussion started by: shuhang2
7 Replies

7. Shell Programming and Scripting

Using 'stat' to determine file system type (with Zenity)

edited and removed (0 Replies)
Discussion started by: mdpalow
0 Replies

8. HP-UX

more than one fs type on the same file system

hi is it possible to have more than one file system types on the same file system. if yes then how do we do it, can veritas be used to achieve this (1 Reply)
Discussion started by: livemyway
1 Replies

9. UNIX for Dummies Questions & Answers

Not able to detect nr of cpu in Solaris System

Hello, how can I detect the nr of cpu of my SUN E250 Solaris server? I have tryed with top but I was not able to find the information. Thanks. (1 Reply)
Discussion started by: pbonato
1 Replies
Login or Register to Ask a Question