Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

SQL Scripts & Samples

Posted Mar 26, 2004

Create user with random password

By DatabaseJournal.com Staff



>>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



SQL Scripts & Samples Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
SQL Scripts & Samples Forum
Topic By Replies Updated
sql help!! add 1 August 22nd, 11:58 AM
How To Combine These 2 Queries into 1 Query ? tarek_land 1 June 7th, 08:37 AM
solving query svibuk 1 February 3rd, 06:08 AM
converting from a character string to uniqueidentifier saturnius 4 January 4th, 05:56 AM


















Thanks for your registration, follow us on our social networks to keep up-to-date