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
You can get the UUID of the root filesystem /
, that is fairly reliable, yet it won't differentiate between chroots and possibly vms running on the same disk.
If you are mainly dealing with internal or static HDD's that are dedicated to running a particular OS then you should be able to use the UUID of the root filesystem to detect the system.
You can get the UUID of the root fs with something like this:
alias sys_guid='sudo /sbin/blkid | grep "$(df -h / | sed -n 2p | cut -d" " -f1):" | grep -o "UUID=\"[^\"]*\" " | sed "s/UUID=\"//;s/\"//"'
If you need to further differentiate between kernel versions of the same OS, or different OS's running on the same disk you can use data from uname
and/or combine them with the root fs UUID.