maroph

Bash: create a UUID value

Aug 30th, 2016
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.82 KB | None | 0 0
  1. # There are several ways to create a UUID in a bash script.
  2. # UUID: https://en.wikipedia.org/wiki/Universally_unique_identifier
  3.  
  4. # Use the Linux kernel
  5. uuid=`cat /proc/sys/kernel/random/uuid`
  6.  
  7. # Tool uuidgen
  8. # Check if the uuidgen tool is available
  9. # https://rpmfind.net/linux/rpm2html/search.php?query=uuidgen
  10. # https://packages.debian.org/sid/uuid-runtime
  11. # https://launchpad.net/ubuntu/precise/+package/uuid-runtime
  12. uuid=`uuidgen`
  13.  
  14. # Java Runtime Environemnt (JRE) 6/7/8
  15. uuid=`jrunscript -e 'java.lang.System.out.print(java.util.UUID.randomUUID().toString());'`
  16.  
  17. # Perl
  18. uuid=`perl -e 'use Data::UUID;print Data::UUID->new->create_str();'`
  19.  
  20. # exit code 2 (ENOENT): module Data or Data::UUID not found
  21.  
  22. # Python 2/3
  23. uuid=`python -c 'import uuid;print uuid.uuid1();'`
  24. uuid=`python3 -c 'import uuid;print(uuid.uuid1());'`
Advertisement
Add Comment
Please, Sign In to add comment