0

I want to generate 100 files with 100 random passwords in /mnt/mymnt/passwords using a script creating some directories.

Even if i try to use cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 30 | head -n 1 > some_random_file.txt the process just does not stop, anyone has any idea why?

4
  • @JeffSchaller uh yeah, fold, sorry and "tr" too
    – C. Cristi
    Commented Nov 19, 2018 at 16:59
  • @KamilMaciorowski it worked but it stopped inserting passwords after the first file, and I don't get why
    – C. Cristi
    Commented Nov 19, 2018 at 17:10
  • On a Side note: Next time Give a try to crunch. That would be much easier than writing a script but If you are into learning rather than achieving some task, writing script is Cool :) Commented Nov 20, 2018 at 4:00
  • Using openssl to generate the random value may help. Take a look at "openssl rand -hex 32" for example.
    – mrflash818
    Commented Nov 22, 2018 at 17:46

1 Answer 1

1

I would do it in the following way:

#!/bin/bash
for i in {1..100}
do
   cat /dev/urandom | tr -dc '_A-Za-z0-9' | head -c${1:-32} > Password$i
done
9
  • 2
    Too many hyphens in the tr character set: tr -dc '_A-Za-z0-9' and you can replace the letters and numbers with a character class: tr -dc '_[:alnum:]' Commented Nov 19, 2018 at 18:58
  • yours is wrong i think
    – C. Cristi
    Commented Nov 20, 2018 at 16:47
  • /dev/urandom uses su or sudo, so the script needs to be run as such. Works on my computer running Debian 9. I see it can be condensed. Thanks glenn! Commented Nov 22, 2018 at 16:57
  • Fixed my error. Can now be ran as normal user also. Forgot cat and one pipe, memory not as good as I thought. :( @C.Cristi Commented Nov 22, 2018 at 17:10
  • I believe that your shell syntax is off a bit.  Look at adding some parentheses and replacing the last | with >. Commented Nov 22, 2018 at 17:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .