Determine OS from a single command line operation

后端 未结 3 1910
粉色の甜心
粉色の甜心 2021-01-28 05:59

Introduction:

I have a \'magic\' tool that can perform a command line operation on a machine if I provide the IP. The tool knows the OS that machine is

相关标签:
3条回答
  • 2021-01-28 06:37

    Safest way to determine Linux/version is

    cat /etc/*release
    

    Sample output.

    DISTRIB_ID=LinuxMint
    DISTRIB_RELEASE=17
    DISTRIB_CODENAME=qiana
    DISTRIB_DESCRIPTION="Linux Mint 17 Qiana"
    NAME="Ubuntu"
    VERSION="14.04.1 LTS, Trusty Tahr"
    ID=ubuntu
    ID_LIKE=debian
    PRETTY_NAME="Ubuntu 14.04.1 LTS"
    VERSION_ID="14.04"
    HOME_URL="http://www.ubuntu.com/"
    SUPPORT_URL="http://help.ubuntu.com/"
    BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
    
    0 讨论(0)
  • 2021-01-28 06:39

    If I understood your problem correctly, then uname is the ideal command. If it's any Unix-system (including OSX), it'll return the correct variable, and if it's Windows it'll return command not found or similar.

    0 讨论(0)
  • 2021-01-28 06:42

    Another command that should work is set, which displays name and value of each environment variable. Any shell on Linux supports it (although output is different between csh and bash). Output from a Windows system would have PROCESSOR_ARCHITECTURE and other standard variables in it (see https://ss64.com/nt/syntax-variables.html), which are very unlikely to be set in Linux.

    0 讨论(0)
提交回复
热议问题