Linux/KSH Random Password

Bizen | Linux | Recent Changes | Preferences

#!/bin/ksh
#
# Random 8 character password generator
#
# I hope you find this 100 times better than the 'tr' method!
#
# Phil Ehrens <phil@slug.org>
#

newpass() {
   typeset junk
   while [[ ${#junk} -lt 8 ]]
   do
      junk=$(/bin/dd if=/dev/urandom bs=1k count=1 2>/dev/null)
      junk=${junk//[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]/}
   done
   print ${junk:0:8}
}

foo=$(newpass)

print $foo

Bizen | Linux | Recent Changes | Preferences

Last edited December 5, 2011 5:11 pm by Pokute
Search Bizen: