Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
Like Tree11Likes
hello I would like to know how i can do a os detection with an action that is dedicated to it Example, I am a user of ubuntu the script ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2013
    Posts
    23

    linux Detection system with dedicate Action ?


    hello
    I would like to know how i can do a os detection with an action that is dedicated to it

    Example, I am a user of ubuntu the script detects my OS and makes the specific action with this system and without actions dedicated to other OS and continue installing the software

    tx

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,752
    Don't know about specific OS detection, but kernel detection is not difficult. Use the 'uname -r' command to see what kernel is currently running the system. For what you say you want to do, you will still have to parse it out a bit, but that is pretty simple. I am running a Red Hat Enterprise Linux clone, Scientific Linux. The uname -r command returns this string: 2.6.32-358.14.1.el6.x86_64 - that indicates it is running a 2.6.32 kernel, that it is an RHEL 6 system (or derived - the el6 substring), and that it is running 64 bits (x86_64).
    narugawa likes this.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Dec 2009
    Location
    California
    Posts
    98
    As rubberman mentioned, you an definitely do things based on the kernel version, but you can also do things based on the OS type...

    For example, I use the following in my $HOME/.profile:
    Code:
    variant=`uname -s` || variant=$(uname -p)
    case "$variant" in
    "SunOS"|"sparc"|"i386")
            NIS_PATH='org_dir.$:$'
            # this cannot be set on contempory version of Solaris, or pretty much
            # every command core dumps
            # lets try again - for mozilla
            addpath LD_LIBRARY_PATH /usr/lib
            addpath LD_LIBRARY_PATH /opt/sfw/lib
            addpath LD_LIBRARY_PATH /usr/openwin/lib
            addpath LD_LIBRARY_PATH /usr/local/lib
    
            # don't rely on system customized paths
            PATH=""; MANPATH=""
            addpath MANPATH /usr/share/man
            addpath MANPATH /usr/openwin/man
            addpath MANPATH /opt/man
            addpath MANPATH /usr/dt/man
    "x86at")
            LD_LIBRARY_PATH=/usr/X/lib
            addpath MANPATH /usr/share/man
            addpath MANPATH /opt/man
            Xbin=/usr/X/bin
            PATH=/bin:/usr/sbin:/opt/bin:/usr/ucb:/usr/ccs/bin:$Xbin
    "HP-UX")
            PATH=/bin:/usr/bin:/usr/local/bin:/usr/ccs/bin:/usr/bin/X11
            ;;
    "Linux")
            # Installed TDI
            TDI_SOLDIR=/home/abarclay/TDI
            export TDI_SOLDIR
            #AWB - flash videos bleed through to black areas with flash 11.2
            VDPAU_NVIDIA_NO_OVERLAY=1
            export VDPAU_NVIDIA_NO_OVERLAY
    ;;
    esac
    Of course, to differentiate between different version of Linux, you would need to look at /etc/redhat-release, etc.... there is a corresponding file on every linux distro.

    Andy
    narugawa likes this.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Aug 2013
    Posts
    23
    hello
    thank you for your answers

    sorry I do not speak English natively and I better explain what I'm looking for

    what I want to do is

    1 - detect os system
    2- Once the os system detect it triggers the specific installation system detect such deposits install and then install the software
    I want my script to be compatible for ubuntu debian fedora and centos
    thank you

  6. #5
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,304
    Hi.

    The most complete OS detection script I know is: http://git.savannah.gnu.org/gitweb/?....guess;hb=HEAD

    It can detect Linux, BSD, etc., but does not distinguish among distributions. For example, on a Debian system, it returns:
    Code:
    x86_64-unknown-linux-gnu
    However, here is a shell function that I use to display information from the /etc/release or issue files:
    Code:
    mii()
    {
      ## mii - massage issue information, if it exists.
      local file
      if [ -f /etc/issue ]
      then
        file=/etc/issue
      elif [ -f /etc/release ]
      then
        file=/etc/release
      else
        echo ""
        return
      fi
      cat $file |
      grep -v '^[     ]*$' |
      head -1 |
      sed -e 's/^[        ]*//' -e 's/^\([^\]*\)[\].*$/\1/'
    }
    
    mii
    Here is what it returns on the systems you specified:
    Code:
    Ubuntu 11.10 (oneiric on Debian wheezy/sid)
    Debian GNU/Linux 7.1 (wheezy)
    Fedora 19 KDE (Schrödinger’s Cat)
    CentOS release 6.4 (Final)
    Your results will probably vary; I often modify the /etc/release files to add information or standardize the format.

    Good luck, best wishes ... cheers, drl
    Last edited by drl; 08-10-2013 at 12:14 PM.
    narugawa likes this.
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  7. #6
    Just Joined! kerim's Avatar
    Join Date
    May 2010
    Location
    Istanbul
    Posts
    15
    if you want to detect your OS and version, you can use this command

    Code:
    lsb_release -a
    output like this:
    Code:
    LSB Version:	1.4
    Distributor ID:	arch
    Description:	Arch Linux
    Release:	rolling
    Codename:	n/a
    You can see more parameters with this command
    Code:
    lsb_release --help
    narugawa likes this.

  8. #7
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,752
    Quote Originally Posted by kerim View Post
    if you want to detect your OS and version, you can use this command

    Code:
    lsb_release -a
    output like this:
    Code:
    LSB Version:	1.4
    Distributor ID:	arch
    Description:	Arch Linux
    Release:	rolling
    Codename:	n/a
    You can see more parameters with this command
    Code:
    lsb_release --help
    I didn't know about this one. Seems to work though! Thanks. My Scientific Linux system (an RHEL clone) returns this from lsb_release -a:
    Code:
    LSB Version:	:base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
    Distributor ID:	Scientific
    Description:	Scientific Linux release 6.4 (Carbon)
    Release:	6.4
    Codename:	Carbon
    kerim and narugawa like this.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  9. #8
    Just Joined! kerim's Avatar
    Join Date
    May 2010
    Location
    Istanbul
    Posts
    15
    Of course simple solution.This is the only simplest and best command.Don't try to find another complex solutions, "lsb_release" is enough
    Rubberman likes this.

  10. #9
    Just Joined!
    Join Date
    Aug 2013
    Posts
    23
    cool thank you for your help ^^ but I do not want that the detection system

    ----------
    translated by my friend
    ----------
    Hi,

    I would like to make my script multi-os compatible and I am having problems to make it work.

    I would like it to be compatible with those 4 linux versions : Ubuntu, Debian, Fedora and Centos.

    I am mostly confused when it comes to the repository installation and the different os dependancies

    Do you have any ideas of how I can make that work?

    I have attached my script to the post.

    I am also new to script programmation and I am open to suggestions and tips.

    Your help is greatly appreciated.

    I can not paste my code ....

    Thank you !

  11. #10
    Just Joined! kerim's Avatar
    Join Date
    May 2010
    Location
    Istanbul
    Posts
    15

    Question Template Script

    Here is a script for your usage.

    Modify for your needs

    This is template

    Code:
    #!/bin/bash
    
    DISTRIBUTOR=$(lsb_release -i | tr '[:upper:]' '[:lower:]' | cut -f 2)
    
    echo "Your OS is : $DISTRIBUTOR"
    echo "Now you os will install to your drive"
    echo "Please be patient"
    sleep 5 
    
    case $DISTRIBUTOR in
    
    ubuntu)
            echo "Installing my package"
            dpkg -i mypackage.deb
            ;;
    debian)
            echo "Installing my package"
            dpkg -i mypackage.deb
            ;;
    fedora)
            echo "Installing my package"
            rpm -ivh mypackage.rpm
            ;;
    centos)
            echo "Installing my package"
            rpm -ivh mypackage.rpm
            ;;
    *)
            echo "Installing tarball from source code"
            tar -zxvf mypackage.tar.gz
            cd mypackage
            make
            make install
            ;;
    esac
    narugawa likes this.

Page 1 of 2 1 2 LastLast

Posting Permissions

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