2017-10-05 12:32:35 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
LENGTH=30
|
2024-01-21 12:56:15 +01:00
|
|
|
CLASS="[:alnum:]-_.:,;*=!<>"
|
2017-10-05 12:32:35 +02:00
|
|
|
|
|
|
|
# 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
|