#!/bin/bash # # A password generator. # # Thu Nov 20 08:23:44 CET 2008 hanr # Fri Feb 26 15:32:41 CET 2010 hanr - extended with special char at the end # SIZE=7 # Length of password without special char CHARARR=( q w e r t z u i o p a s d f g h j k l y x c v b n m Q W E R T Z U I O P A S D F G H J K L Y X C V B N M 1 2 3 4 5 6 7 8 9 0 ) # Array filling with chars SPCHARARR=( ! . = + - ) # Array filling with special chars TOTELEMCHAR=${#CHARARR[*]} # Number of elements in char array TOTELEMSPCHAR=${#SPCHARARR[*]} # Number of elements in special char array COUNTER=0 # Counter for loop while [ $COUNTER -lt $SIZE ] do COUNTER=`expr $COUNTER + 1` # Increment CHARINDEX=$(($RANDOM%$TOTELEMCHAR)) # Random indexnumber inside the array length with modulo PASS=$PASS"${CHARARR[$CHARINDEX]}" # Attach the char in the element to the password until its length done if [ ! `echo $PASS |egrep [0-9] >/dev/null` ]; then # If the passwd hasn't at least one numeric digit, PASS=`echo $PASS |cut -b1-6` # delete the last element PASS=$PASS"$(($RANDOM%9))" # and attach a random number from 0-9 at the end fi SPCHARINDEX=$(($RANDOM%$TOTELEMSPCHAR)) # Random indexnumber inside the array length with modulo PASS=$PASS"${SPCHARARR[$SPCHARINDEX]}" # Attach the special char in the element to the password echo $PASS # print the password exit 0