Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Oracle user creation script

Status
Not open for further replies.

octar

Technical User
Oct 21, 2002
28
AU
Hi, I have the following script to create oracle users on our system, it works but please tell me an easier way???

-----------------------
Format of oracle_userlist file -> DATABASE USERID PASSWORD GROUP
--------------------------

#/usr/bin/ksh

NUMBER_OF_USERS=`cat oracle_userlist | wc -l`
CURRENT_LINE=1

while [[ $CURRENT_LINE -le $NUMBER_OF_USERS ]]
do
rm user.txt
DATABASE=`head -n$CURRENT_LINE < oracle_userlist | tail -n1 | cut -f 1 -d &quot; &quot;`
USERID=`head -n$CURRENT_LINE < oracle_userlist | tail -n1 | cut -f 2 -d &quot; &quot;`
PASSWORD=`head -n$CURRENT_LINE < oracle_userlist | tail -n1 | cut -f 3 -d &quot; &quot;`
GROUPID=`head -n$CURRENT_LINE < oracle_userlist | tail -n1 | cut -f 4 -d &quot; &quot;`

echo &quot;connect internal;&quot; >> user.txt
echo &quot;create user $USERID identified by $PASSWORD default tablespace users temporary tablespace temp;&quot; >> user
.txt
echo &quot;grant $GROUPID to $USERID identified by $PASSWORD;&quot; >> user.txt

echo &quot;select * from dba_users where username='$USERID';&quot; >> user.txt

/bin/su - oracle -c &quot;DATABASE=$DATABASE;svrmgrl&quot; < user.txt

rm user.txt
CURRENT_LINE=`expr $CURRENT_LINE + 1`
done
 
It looks simple enough, how would you want it simplified?
To take input from the command line? or to have an option of command line or input file?
 
I would prefer a better way to read each complete line of the file instead of using
-> head -n$CURRENT_LINE < oracle_userlist | tail -n1 <-
Also to get away from using the user.txt file?
I know it works, but I also know there is probably an easier way, possibly using sed ??
 
Another way

#/usr/bin/ksh

cat oracle_userlist | while read LINE; do
DATABASE=`echo $LINE | awk '{print $1}'`
USERID=`echo $LINE | awk '{print $2}'`
PASSWORD=`echo $LINE | awk '{print $3}'`
GROUPID=`echo $LINE | awk '{print $4}'`

sqlplus system/<system pass>@$DATABSE << EOF
create user $USERID identified by $PASSWORD
default tablespace users
temporary tablespace temp;
EOF

done

--------------------------
Using user system to create a user into a script is not the best idea, just to see how it works.

Check instead if the user ops$oracle is availabe to do it.

if so, change with:

#/usr/bin/ksh

cat oracle_userlist | while read LINE; do
DATABASE=`echo $LINE | awk '{print $1}'`
USERID=`echo $LINE | awk '{print $2}'`
PASSWORD=`echo $LINE | awk '{print $3}'`
GROUPID=`echo $LINE | awk '{print $4}'`

export ORACLE_SID=$DATABASE
sqlplus / << EOF
create user $USERID identified by $PASSWORD
default tablespace users
temporary tablespace temp;
EOF

done

-----------
EDC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top