This will allow you to check for existing user names...
Code:
grep "^$1:" /etc/passwd > /dev/null
if [ $? = 0 ]; then
USERID=$1
SERVERNAME=$(hostname)
filename=$SERVERNAME-$USERID
randpass
outputfile
passchange
else
echo "User $1 does not exist."
fi
Also, I dont like how you're writing the credentials to the file system. At minumum, you should do some strict access enforcement (chmod) on the file before writing the password to the file so normal users can have access to it. "shred -n3 -u" to remove the data would have limited use on a journaled filesystem.
Best case, you should pipe the information to gpg, encrypted to each user before it's emailed. But that would require a whole lot more prerequisits... like users having to know how to use pgp.