'How to generate a uuid in shell script [duplicate]
Is there a way to generate uuid in shell script, similar to $RANDOM, can i use $uuidgen to get a uuid, or do i need to install any package to generate a uuid in shell script
#!/bin/bash
echo $RANDOM
echo $uuid
Solution 1:[1]
From this rather comprehensive article.
http://0pointer.de/blog/projects/ids.html
(btw, that's the blog of Lennart Poettering)
Linux offers a kernel interface to generate UUIDs on demand, by reading from /proc/sys/kernel/random/uuid
This is a very simple interface to generate UUIDs. That said, the logic behind UUIDs is unnecessarily complex and often it is a better choice to simply read 16 bytes or so from /dev/urandom
Solution 2:[2]
check this out, I have the exact same issue and I have solved it this way, ignore what the code is doing, just put attention on the sections were I'm using the uuidgen.
#!/bin/bash
# Create 100000 small files between 1K and 100K and stored in $2 directory
# sh create_small_files.sh 1000 small_3
MAX=$1
DIR=$2
for i in $(seq $MAX)
do
for y in $(shuf -i 1-100 -n 100)
do
name=$(uuidgen)
dd if=/dev/urandom of=./$2/$name bs=${y}k count=1
done
done
I'm using fedora 29, so in order to have this command you need to install this.
util-linux-2.32.1-1.fc29.x86_64 : A collection of basic system utilities
Repo : fedora
Matched from:
Filename : /usr/bin/uuidgen
Cheers.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Daniel Ruf |
