Getting a unique id from a unix-like system

前端 未结 15 2453
不知归路
不知归路 2020-11-27 18:22

I want to get from any Unix-like system (if this is possible) a unique id that will be persistent every time my application runs in the same machine. If it is possible, I wa

15条回答
  •  星月不相逢
    2020-11-27 18:55

    As someone else stated, the dmidecode command is an option.

    [root@sri-0000-0003 WebGui]# dmidecode -s system-uuid
    03001234-1234-1234-1234-000700012345
    

    I edited the output to hide the UUID of the system I tested on.

    There are other things that you can get from dmidecode. dmidecode -t will tell you the categories.

    [root@sri-0000-0003 WebGui]# dmidecode -t
    dmidecode: option requires an argument -- 't'
    Type number or keyword expected
    Valid type keywords are:
      bios
      system
      baseboard
      chassis
      processor
      memory
      cache
      connect
    

    If you're using actual hardware instead of a virtual machine then dmidecode -t processor would be a good option.

    [root@sri-0000-0003 WebGui]# dmidecode -t processor
    # dmidecode 3.1
    Getting SMBIOS data from sysfs.
    SMBIOS 3.0.0 present.
    
    Handle 0x0041, DMI type 4, 48 bytes
    Processor Information
            Socket Designation: U3E1
            Type: Central Processor
            Family: Core i3
            Manufacturer: Intel(R) Corporation
            ID: E3 00 00 00 11 22 33 44
    

    Given that the number of processor manufactures is small, this seems like a good alternate to dmidecode -s system-uuid. However, under virtualbox, dmidecode -t processor won't give you anything useful. I don't know about any other virtual platforms.

    I'm willing to bet that dmidecode -s system-uuid will also work inside a docker container too but, I can't verify that.

提交回复
热议问题