Need to generate a file with random data. /dev/[u]random doesn't exist.

Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom.

I create a named pipe then:

dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024

but when I cat a file to the fifo that's 1024 random bytes:

cat randomfile.txt > mynamed.fifo;

the dd command exits writing only 1024 (Likely the EOF thing). so I never get my 1MB file. How do I get around this? How do I ensure it generates the random data file without closing dd? Is there something else I need to pass?

Cheers,
DH

Why not just read/write the first 1MB from file(randomfile.txt) to another file:

head -c1MB randomfile.txt > test.txt

What system doesn't have /dev/urandom? What languages do you have available?

How about this? When dd quits, it should kill the while-loop too. No named pipe needed.

while true
do
        cat inputfile
done | dd bs=1024 count=1024 > outputfile

Could you use openssl to generate your random file directly, e.g. for 1Mb file use:

$ openssl rand 1048576 > myfile.fifo
1 Like

Thanks very much all for the replies. Really appreciate it. The place to run this for me would be even in basic shells like the Linux, Solaris, AIX etc 'maintenance' / 'recovery' shells.

So things like Perl or openssl won't work as required libraries won't be loaded in those simple recovery shells.

Corona688:
That's a good option there but unfortunately it didn't work fully or I should say it DID work partially. The loop continued to run even though the dd command ended / stopped.

Cheers,
DH

How about just using dd to append to file each time:

$ dd if=randomfile1.txt of=myfile.fifo oflag=append conv=notrunc
$ dd if=randomfile2.txt of=myfile.fifo oflag=append conv=notrunc
$ dd if=randomfile1.txt of=myfile.fifo oflag=append conv=notrunc

Thinking laterally, a long shot, but worth a try...

Not sure why you need to use 1024 for block size, but my dd command will accept a bs of 1048576 so...

dd if=mynamed.fifo of=myfile.fifo bs=1048576 count=1

Hey Guy's,

I haven't tried the conv= or the oflag= . I'll give these a spin and see how they work. Need to first check if they're universally available. Tried seek= and count= as well. That seemed to do the job.

Cheers,
DH