How to Generate a per-Host UUID in a Shell Script?
<p>I am writing a shell script that will be deployed to multiple machines and connect to a central server. When connecting, the script should identify the machine it is running on. (This is used to implement some rudimentary locking but that's not important for the question.)</p>

<p>I know that I could use the host-name, as reported by <code>hostname -f</code>, to identify the machine. But many personal devices have far from unique host-names, such as <code>my-laptop</code> or <code>workstation</code> so I'm wary of using this.</p>

<p>I might be able to add entropy by hashing the host-name together with some other host-specific information that will not change.</p>

<pre><code>echo $(hostname -f) $(uname -snmpio) | md5sum
</code></pre>

<p>But the added entropy is very low. I'm having a hard time thinking of other system properties that can be hashed and are guaranteed not to change. (For example, I don't want to add any properties of the file system or other system configuration<sup>1</sup> because it might legitimately change at any time.)</p>

<p>Finally, I thought about generating a random string the first time the script is run and store it in some configuration file. This wold be extremely likely to be unique and guaranteed not to change. But if possible, I'd prefer not having to manage persistent state.</p>

<p>Ideally, there would exist a utility to obtain a deterministic non-volatile UUID for the local system (like <code>blkid</code> for block-devices). It is not required that the UUIDs be hard to forge. This is not an authentication mechanism and I'm trusting all parties that run the script.</p>

<p>Are there any superior options I have overlooked?</p>

<hr>

<p><sup>1</sup> Technically, the host-name is a system configuration, too. But if we change it, we <em>expect</em> the system to no longer be identified as the one it was before.</p>