Results 1 to 3 of 3

Thread: Script to Check for OS

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Script to Check for OS

    Hi,

    I am looking for a script to run in both Linux and Solaris. The script should basically check the operating system and then if it is Linux it has to execute a particular part of the script related to Linux or else it will have to run the part of the script pertaining to Solaris.

    Please advise...

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,498
    Thanks
    17
    Thanked 788 Times in 506 Posts
    Rep Power
    10

    Default

    Code:
    #!/bin/sh
    os=`uname`
    
    if [ "$os" == "Linux" ] 
    then
      callLinuxFunction
    fi
    
    if [ "$os" == "SunOS" ] 
    then
      callSunOSFunction
    fi
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    12
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Rep Power
    0

    Default

    Quote Originally Posted by si203n View Post
    Hi,

    I am looking for a script to run in both Linux and Solaris. The script should basically check the operating system and then if it is Linux it has to execute a particular part of the script related to Linux or else it will have to run the part of the script pertaining to Solaris.

    Please advise...
    Hi,
    As you said that you want to run this only on two operation system. then this would be sufficient:
    #!/bin/sh
    os=`uname`

    if [ "$os" == "Linux" ]
    then
    callLinuxFunction
    else
    callSunOSFunction
    fi

    No need to use two different If statements. And if you want to use the same thing on other operation systems ( that you want to run this on linux,HP-UX,Solaris) I suggest you to use CASE for that.

    Thanks and Regards,
    Kunal

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. shell script to open log files and check for faults
    By trueman82 in forum Shell scripting
    Replies: 3
    Last Post: 26th March 2013, 09:33 AM
  2. Replies: 4
    Last Post: 10th March 2011, 05:59 PM
  3. Shell Script To Check the Status of All Linux Service
    By linux12 in forum Shell scripting
    Replies: 1
    Last Post: 2nd February 2011, 12:44 PM
  4. PERL Script to check file on directory
    By mitchiekoy in forum Coding in General
    Replies: 15
    Last Post: 29th December 2010, 10:36 AM
  5. script on how to check if the file exists
    By warren in forum Shell scripting
    Replies: 4
    Last Post: 14th April 2006, 05:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •