Trying to generate random password characters into a file











up vote
0
down vote

favorite












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?










share|improve this question
























  • @JeffSchaller uh yeah, fold, sorry and "tr" too
    – C. Cristi
    Nov 19 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 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 at 4:00










  • Using openssl to generate the random value may help. Take a look at "openssl rand -hex 32" for example.
    – mrflash818
    2 days ago















up vote
0
down vote

favorite












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?










share|improve this question
























  • @JeffSchaller uh yeah, fold, sorry and "tr" too
    – C. Cristi
    Nov 19 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 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 at 4:00










  • Using openssl to generate the random value may help. Take a look at "openssl rand -hex 32" for example.
    – mrflash818
    2 days ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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?










share|improve this question















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?







shell scripting password






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked Nov 19 at 16:54









C. Cristi

1647




1647












  • @JeffSchaller uh yeah, fold, sorry and "tr" too
    – C. Cristi
    Nov 19 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 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 at 4:00










  • Using openssl to generate the random value may help. Take a look at "openssl rand -hex 32" for example.
    – mrflash818
    2 days ago


















  • @JeffSchaller uh yeah, fold, sorry and "tr" too
    – C. Cristi
    Nov 19 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 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 at 4:00










  • Using openssl to generate the random value may help. Take a look at "openssl rand -hex 32" for example.
    – mrflash818
    2 days ago
















@JeffSchaller uh yeah, fold, sorry and "tr" too
– C. Cristi
Nov 19 at 16:59






@JeffSchaller uh yeah, fold, sorry and "tr" too
– C. Cristi
Nov 19 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 at 17:10




@KamilMaciorowski it worked but it stopped inserting passwords after the first file, and I don't get why
– C. Cristi
Nov 19 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 at 4:00




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 at 4:00












Using openssl to generate the random value may help. Take a look at "openssl rand -hex 32" for example.
– mrflash818
2 days ago




Using openssl to generate the random value may help. Take a look at "openssl rand -hex 32" for example.
– mrflash818
2 days ago










1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










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





share|improve this answer










New contributor




Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • 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 at 18:58










  • yours is wrong i think
    – C. Cristi
    Nov 20 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
    2 days ago












  • 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
    2 days ago












  • I believe that your shell syntax is off a bit.  Look at adding some parentheses and replacing the last | with >.
    – G-Man
    2 days ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482803%2ftrying-to-generate-random-password-characters-into-a-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










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





share|improve this answer










New contributor




Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • 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 at 18:58










  • yours is wrong i think
    – C. Cristi
    Nov 20 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
    2 days ago












  • 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
    2 days ago












  • I believe that your shell syntax is off a bit.  Look at adding some parentheses and replacing the last | with >.
    – G-Man
    2 days ago















up vote
0
down vote



accepted










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





share|improve this answer










New contributor




Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • 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 at 18:58










  • yours is wrong i think
    – C. Cristi
    Nov 20 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
    2 days ago












  • 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
    2 days ago












  • I believe that your shell syntax is off a bit.  Look at adding some parentheses and replacing the last | with >.
    – G-Man
    2 days ago













up vote
0
down vote



accepted







up vote
0
down vote



accepted






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





share|improve this answer










New contributor




Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









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






share|improve this answer










New contributor




Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer








edited 2 days ago





















New contributor




Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered Nov 19 at 18:46









Michael Prokopec

43711




43711




New contributor




Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 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 at 18:58










  • yours is wrong i think
    – C. Cristi
    Nov 20 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
    2 days ago












  • 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
    2 days ago












  • I believe that your shell syntax is off a bit.  Look at adding some parentheses and replacing the last | with >.
    – G-Man
    2 days ago














  • 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 at 18:58










  • yours is wrong i think
    – C. Cristi
    Nov 20 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
    2 days ago












  • 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
    2 days ago












  • I believe that your shell syntax is off a bit.  Look at adding some parentheses and replacing the last | with >.
    – G-Man
    2 days ago








2




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 at 18:58




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 at 18:58












yours is wrong i think
– C. Cristi
Nov 20 at 16:47




yours is wrong i think
– C. Cristi
Nov 20 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
2 days ago






/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
2 days ago














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
2 days ago






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
2 days ago














I believe that your shell syntax is off a bit.  Look at adding some parentheses and replacing the last | with >.
– G-Man
2 days ago




I believe that your shell syntax is off a bit.  Look at adding some parentheses and replacing the last | with >.
– G-Man
2 days ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482803%2ftrying-to-generate-random-password-characters-into-a-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Morgemoulin

Scott Moir

Souastre