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?

  • @JeffSchaller uh yeah, fold, sorry and "tr" too – C. Cristi Nov 19 '18 at 16:59
  • @KamilMaciorowski it worked but it stopped inserting passwords after the first file, and I don't get why – C. Cristi Nov 19 '18 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 :) – C0deDaedalus Nov 20 '18 at 4:00
  • Using openssl to generate the random value may help. Take a look at "openssl rand -hex 32" for example. – mrflash818 Nov 22 '18 at 17:46

I would do it in the following way:

for i in {1..100}
   cat /dev/urandom | tr -dc '_A-Za-z0-9' | head -c${1:-32} > Password$i
  • 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:]' – glenn jackman Nov 19 '18 at 18:58
  • yours is wrong i think – C. Cristi Nov 20 '18 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! – Michael Prokopec Nov 22 '18 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 – Michael Prokopec Nov 22 '18 at 17:10
  • I believe that your shell syntax is off a bit.  Look at adding some parentheses and replacing the last | with >. – G-Man Says 'Reinstate Monica' Nov 22 '18 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.