Bashでパスワードを動的に生成するスクリプト

アカウント発行を自動化する際などで初期パスワードを生成するスクリプトです

#!/bin/sh
str_seed1="abcdefghijklmnopqrstuvwxyz"
str_seed2="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
str_seed3="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
str_seed4="0123456789"
str_seed5="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

pass=""
count=0
while [ $count -lt 1 ]; do
    ran=`expr $RANDOM % 26 + 1`
    char=`expr substr $str_seed1 $ran 1`
    pass=$pass$char
    count=`expr $count + 1`
done
count=0
while [ $count -lt 2 ]; do
    ran=`expr $RANDOM % 10 + 1`
    char=`expr substr $str_seed4 $ran 1`
    pass=$pass$char
    count=`expr $count + 1`
done
count=0
while [ $count -lt 4 ]; do
    ran=`expr $RANDOM % 62 + 1`
    char=`expr substr $str_seed5 $ran 1`
    pass=$pass$char
    count=`expr $count + 1`
done
count=0
while [ $count -lt 3 ]; do
    ran=`expr $RANDOM % 26 + 1`
    char=`expr substr $str_seed2 $ran 1`
    pass=$pass$char
    count=`expr $count + 1`
done
count=0
while [ $count -lt 2 ]; do
    ran=`expr $RANDOM % 52 + 1`
    char=`expr substr $str_seed3 $ran 1`
    pass=$pass$char
    count=`expr $count + 1`
done
echo ${pass}