#!/bin/bash
# Number of letters as argument, default 7
if [ “$1” != “” ]; then
num=$1
else
num=7
fi
generate() {
# Take 1 block from /dev/urandom, encode it base64,
# remove first two and last status line, purge capital letters and
# special characters from output, cut desired length from front
# sed with [A-Z] doesn’t work with Suse - typical!
password=$(dd if=/dev/urandom count=1 2>/dev/null | uuencode -m - \
| head -n 2 | tail -n 1 | sed -e ’s:[/+A-Z]::g’ | cut -c -$num)
}
# Repeat until letters AND digits occur
while true; do
generate
if echo $password | grep [a-z] | grep [0-9]; then break; fi
done