SHARE
Facebook X Pinterest WhatsApp

Create user with random password

Mar 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: $passwordif [ -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

Recommended for you...

What Backups Do I Have?
Gregory Larsen
May 12, 2021
Improving the Performance of a Table Variable using Optimizer Hint RECOMPILE
Gregory Larsen
Apr 1, 2021
TYPE Definition Change in Oracle 21c
Tip 74 – Changing Cost Threshold for Parallelism
Gregory Larsen
Feb 24, 2021
Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.