Skip to content

Instantly share code, notes, and snippets.

@SomajitDey
Last active September 26, 2021 16:08
Show Gist options
  • Save SomajitDey/49d30b38b194edad8d5b66a448a44b2a to your computer and use it in GitHub Desktop.
Save SomajitDey/49d30b38b194edad8d5b66a448a44b2a to your computer and use it in GitHub Desktop.
Bash script to generate 128-bit Universally/Globally Unique Identifiers in GNU/Linux
#!/usr/bin/env bash
# Description: A simple way to generate 128-bit Universally/Globally Unique Identifiers in GNU/Linux
# Usage: ./UUID-GUID.bash ["Any text you wanna put in"]
# Remark: Perhaps the use of so many variables is overkill, but Hey! It's fun ;-)
# Author: Somajit Dey <[email protected]> 2021
user_element="${1}" # Passed by the user as parameter (optional)
device_element="$(cat /sys/class/net/eth0/address)" # MAC address
time_element="${EPOCHREALTIME}::${SECONDS}" # Spacer :: makes sure 1278-900 != 127-8900 e.g.
randomness_element="${RANDOM}::${SRANDOM}" # Other :: are just to make things consistent
history_element="${BASHPID}::${PPID}-${PWD}::${OLDPWD}-${HISTCMD}" # Spacer - separates contexts
unique_string="${user_element}-${device_element}-${time_element}-${randomness_element}-${history_element}"
md5sum <(echo "${unique_string}") | cut -d ' ' -f 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment