Databases
cancel
Showing results for 
Search instead for 
Did you mean: 

scripts to create a user copying from an existing one

SOLVED
Go to solution
Arturo Galbiati
Esteemed Contributor

scripts to create a user copying from an existing one

Hi Gurus,
I'm looking for a script to allow me to create a new Oracle user copying it from an already existing one? (hpUX11.00 Oracle 8.1.7.4)
TIA.
Art
8 REPLIES
RAC_1
Honored Contributor

Re: scripts to create a user copying from an existing one

user_name=`grep -i "oracle_user" /etc/passwd|awk -F : '{print $1}'`
user_uid=`grep -i "oracle_user" /etc/passwd|awk -F : '{print $3}'`
group=`grep -i "oracle_user" /etc/passwd|awk -F : '{print $4}'
comment=`grep -i "oracle_user" /etc/passwd|awk -F : '{print $5}'`
home_dir=`grep -i "oracle_user" /etc/passwd|awk -F : '{print $6}'`
user_shell=`grep -i "oracle_user" /etc/passwd|awk -F : '{print $7}'`

useradd -u "$((user_uid+1)) -g $group -G "secondary_groups" -m -k /home_dir -s $user_shell "user_name_you_want"

But why all this??

vipw and cut paste business.

Anil
There is no substitute to HARDWORK
Yogeeraj_1
Honored Contributor

Re: scripts to create a user copying from an existing one

hi,

try spooling the following sql to a script and in turn running the script on the other database.

select 'create user '||username||' identified by values '''||password||'''
temporary_tablespace '||temporary_tablespace||' default_tablespace '||default_tablespace||';'
from dba_users;

hope this helps!
regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: scripts to create a user copying from an existing one

hi,

Is it not at the database level??

Anil gave you the commands to be executed at the OS level...

let us know.

regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Indira Aramandla
Honored Contributor

Re: scripts to create a user copying from an existing one

Hi Art,

If you were asking to create a user in a database same as defined in the other database then as Yaoggeraj gave the script will help you to create the user.

And if you want the user data (if any) to be copied to the other database then export from the source database as owner = and then import to the target database as fromuser= and touser=....parameters.


Indira A
Never give up, Keep Trying
Arturo Galbiati
Esteemed Contributor

Re: scripts to create a user copying from an existing one

Hi Gurus,
I'm looking for a SQL script to create a new user copying it from another one that alkready exists.
i.e.: copyuser.sql newuser olduser
The script by Yogi it's ok but it only the first step. I need to copy also the roles/priviledges which from old user to the new user.
Art
Sanjay Kumar Suri
Honored Contributor
Solution

Re: scripts to create a user copying from an existing one

Hello

Check the following two links:

http://www.orafaq.com/scripts/sql/cre8like.txt
http://mylxhq.com/clubs/o/html/modules.php?name=News&file=article&sid=107

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Eric Antunes
Honored Contributor

Re: scripts to create a user copying from an existing one

You can use Oracle Security Manager from Oracle Enterprise Manager to do this: you have an optoin called "Create Like..."
Each and every day is a good day to learn.
Arturo Galbiati
Esteemed Contributor

Re: scripts to create a user copying from an existing one

Thanks sks and Eric