#!/bin/bash #This program is free software; you can redistribute it and/or modify #it under the terms of the GNU General Public License version 2 as published by #the Free Software Foundation. #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details: #http://www.gnu.org/copyleft/gpl.html if [ $# != 1 ] || echo $1 | grep '[^0-9]' &> /dev/null then echo "Error. Arguments must consist of a single positive integer." 3>&1 1>&2 2>&3 exit 1 fi NUMCHARS=$1 NEWPASS="" OK=false while ! $OK do if [ ${#NEWPASS} -ge $NUMCHARS ] then OK=true echo $NEWPASS | cut -c -$NUMCHARS unset NEWPASS else NEWPASS=$NEWPASS`dd bs=$NUMCHARS count=1 if=/dev/urandom 2> /dev/null | perl -e 'my $input = <>; my @letters = split(//, $input); for my $go (@letters) {if ($go =~ /[a-zA-Z0-9]/) { print "$go" }};'` fi done