In bash script, how to generate a random string

I need to generate many random alphanumeric strings, which also use capital letters. It needs to start with 3 characters (e.g. Dk6) and then, with a while loop, go up to about 9 characters (e.g. D7H3j8Sjx). Also, I'm using sshpass and I need to check when it's the correct password, then stop. I know that to guess the password, it would take a very long time, but it would also help if it guessed it by going aaa, aab, aac, aad... aaz, aa1 etc.

4

1 Answer

This function

 function letter() { s=abcdefghijklmnopqrstuvxwyz p=$(( $RANDOM % 26)) echo -n ${s:$p:1} }

generates a random letter. You can substitute abc... for the list of characters you wish to use, count them, and substitute their number to the 26 in line 3.

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like