Created
February 11, 2011 23:03
-
-
Save romaonthego/823230 to your computer and use it in GitHub Desktop.
Bash script: genpassword
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
charspool=('a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' | |
'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' '0' '1' '2' '3' '4' '5' '6' '7' | |
'8' '9' '0' 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' | |
'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z' '-' '_'); | |
len=${#charspool[*]} | |
if [ $# -lt 1 ]; then | |
num=20; | |
else | |
num=$1; | |
fi | |
randomnumbers=$(head -c $num /dev/urandom | od -t u1 | awk '{for (i = 2; i <= NF; i++) print $i}') | |
echo -n "password: " | |
for c in $randomnumbers; do | |
echo -n ${charspool[$((c % len))]} | |
done | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation: sudo nano /usr/bin/genpassword && chmod +x /usr/bin/genpassword
via Dan Sosedoff: http://github.com/sosedoff