dcsimg

Create user with random password

March 26, 2004



>>Script Language and Platform: Oracle
This script is useful for when you want to create a user with a random password.

Author: Vedi Hartono


#!/usr/bin/ksh
SID=$1
echo $SID
export ORACLE_SID=${SID}

echo "userid (password will be generated)"
read userid
set -A M 0 1 2 3 4 5 6 7 8 9 \
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
L="8"

password=""
while [ $L -gt 0 ]
do
password="$password${M[$(($RANDOM%${#M[*]}+1))]}"
L="$(($L-1))"
done
if [ -z "${userid}" ] || [ -z "${password}" ] ; then
echo "wrong number of items entered. Press to quit."
read nothing
exit
fi

### DOES USER ALREADY EXIST? IF SO, EXIT ###

check_the_user()
{
sqlplus -s <internal
set pages 0 lines 150 head off veri off feed off term off echo off
select count(*) from dba_users where username = upper('${userid}');
END
}

if [[ `check_the_user` -gt 0 ]] ; then
echo "ERROR -- user ${userid} already exists - to exit."
read nothing
exit
fi

echo "userid ${userid}"
echo "newpassword: $password"

if [ -z "${userid}" ] || [ -z "${password}" ] ; then
echo "wrong number of items entered. Press to quit."
read nothing
exit
fi

echo " is this correct (y/n)?"
yesno="n"
read yesno
if [ -z "${yesno}" ] || [ ${yesno} != "Y" ] && [ ${yesno} != "y" ] ; then
exit
fi

sqlplus -s <internal
set pages 0 lines 150 head off veri off feed off term off echo off

create user ${userid}
identified by "$password"
default tablespace data01
temporary tablespace temp
QUOTA UNLIMITED ON DATA01
QUOTA 0 ON SYSTEM ;
GRANT SSE_ROLE TO ${userid} ;
exit
ENDSQL

echo "All done. Press to continue."
read nothing

exit

Disclaimer: We hope that the information on these script pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided "as -is", without any warranty, whether express or implied, of its accuracy, completeness, or fitness for a particular purpose... Disclaimer Continued


Back to Database Journal Home








The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers