From a125194f4b5e16ad436b7dd1b6e6be42370a8105 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Thu, 5 Oct 2017 12:32:35 +0200 Subject: [PATCH] Add script genpw --- bin/genpw | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 bin/genpw diff --git a/bin/genpw b/bin/genpw new file mode 100755 index 0000000..82245a0 --- /dev/null +++ b/bin/genpw @@ -0,0 +1,33 @@ +#!/bin/bash + +LENGTH=30 +CLASS="[:alnum:]" + +# Show usage +if [ "$1" == "--help" ]; then + echo "Usage: $0 [length] [class]" + echo "Default length: 30" + echo "Default class: $CLASS (see 'man tr')" + exit 0 +fi + +# Set length if given +if [ "$1" != "" ] && [ $1 -gt 0 ]; then + LENGTH=$1 +fi + +shift + +# Set class if given +if [ "$1" != "" ]; then + CLASS=$1 +fi + + +echo "Generating from /dev/urandom with length $LENGTH using class $CLASS." + +PW=`cat /dev/urandom | tr -dc "$CLASS" | head -c $LENGTH` +echo "Generated password: $PW" +PW="XXXX" + +exit 0