Skip to content

Instantly share code, notes, and snippets.

@furu-nob
Last active July 1, 2016 09:18
Show Gist options
  • Save furu-nob/4e6cc953004763957122a12d4bb2cc0d to your computer and use it in GitHub Desktop.
Save furu-nob/4e6cc953004763957122a12d4bb2cc0d to your computer and use it in GitHub Desktop.
#!/bin/sh
function USAGE {
cat <<EOL
Script for create password.
Usage
$0 [count]
EOL
exit 0
}
function PWGEN {
while :
do
MAKEDPASSWD=$(/usr/bin/pwgen -An ${DIGITS} 1)
PASSWD=$(echo ${MAKEDPASSWD} | grep [${MATCH_LIST}])
test -z ${PASSWD} && test $( echo ${MAKEDPASSWD} |awk '{ count += gsub(/[0-9]/, ""); print count}') -eq 2 && break
done
echo ${MAKEDPASSWD}
}
DIGITS=12
COUNT=${1:-1}
MATCH_LIST='190gijloqvu'
test ${COUNT} = --help && USAGE
expr ${COUNT} + 1 >/dev/null 2>&1
RESULT=$?
test ${RESULT} -ne 0 && echo "${COUNT} is not numeric." && USAGE
while [[ $i -lt ${COUNT} ]]
do
PWGEN
i=$((i+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment