Creating oracle user and giving him grants using shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating oracle user and giving him grants using shell script
# 1  
Old 09-06-2009
Creating oracle user and giving him grants using shell script

Hi ,
I want to write a shell script that can create oracle database user and grants permission to this user.

Thanks & Regards,
Deepak
# 2  
Old 09-06-2009
Quote:
Originally Posted by Deepakjha
...
I want to write a shell script that can create oracle database user and grants permission to this user.
...
Code:
$ echo "create user user1 identified by password1;
grant privilege to user1;
exit
" | sqlplus user2/password2@SID

tyler_durden
# 3  
Old 10-10-2009
Hi durden_tyler,
Thank you for replying, but I am sorry to say that I am not able to understand and execute what you have posted. Could you please explain me in detail.

I want to execute following command using shell script

create user <Username> identified by <Password>;

grant create session, create table, create procedure,create sequence, create view, create trigger,create synonym, create materialized view,
query rewrite, create any directory, create type,dba, aq_administrator_role to <Username>;
# 4  
Old 10-10-2009
Hi.

It prints some SQL to standard output. This output is read by SQL*Plus as input, and works just fine.

Another option:

Code:
sqlplus / as sysdba << !
grant create session, create table, create procedure,
      create sequence, create view, create trigger,
      create synonym, create materialized view, query rewrite,
      create any directory, create type,dba, aq_administrator_role
to username identified by password;
!


$ ./CreateUser
...
Grant succeeded.

$ sqlplus username/password

SQL*Plus: Release 10.2.0.3.0 - Production on Sat Oct 10 14:41:33 2009

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning and Data Mining options

SQL> show user
USER is "USERNAME"

---
Having read your post again, and appreciating that your difficulty might be more with the shell itself, and not with the database side:

Copy and paste this (or durden_tyler's) script into a file:
Code:
sqlplus / as sysdba << !
grant create session, create table, create procedure,
      create sequence, create view, create trigger,
      create synonym, create materialized view, query rewrite,
      create any directory, create type,dba, aq_administrator_role
to username identified by password;
!

modifying it to suit your requirements.

Assume you called the file CreateUser, run the command to make the script executable for you:

Code:
chmod u+x CreateUser

And then run it:
Code:
./CreateUser


Last edited by Scott; 10-10-2009 at 01:29 PM..
# 5  
Old 10-10-2009
Thanks scottn, for such a nice explanation.... I am able to create user and grants as well....
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sql command inside shell script runs without giving anything back as outout

#!/bin/sh # This script returns the number of rows updated from a function echo "The execution is starting ....." sqlplus -silent $UP <<EOF set serveroutput on set echo off set pagesize 0 VAR no_rows_updated NUMBER; EXEC :no_rows_updated :=0; DECLARE CURSOR c_update is SELECT * FROM... (4 Replies)
Discussion started by: LoneRanger
4 Replies

2. Shell Programming and Scripting

How the user will provide the parameters for Oracle db connection in a shell script?

I'm new into unix. My question: is possible to write a shell script which will ask for the ORACLE_HOME, ORACLE_SID, USERNAME, PASSWORD to connect to Oracle db. In generally we have to set the ORACLE_HOME in .profile file. And after putting the 'sqlplus' command it asks for the username &... (6 Replies)
Discussion started by: priya001
6 Replies

3. Shell Programming and Scripting

shell script is giving different resultControlled Special Account [csdwmast@ucdoud01.am.sony.com

Hi All, In this below script i am not able to find where is "form mail id" is taking when this script is executing i am getting "Controlled Special Account " as from ,i need to send "form mail id " from a table.:mad: kindly help me plzz. Regards, Krupa (0 Replies)
Discussion started by: krupasindhu18
0 Replies

4. Shell Programming and Scripting

Giving automatic multiple Input to a tool from shell script

Hi, Please help me,its urgent. I have a tool that i want to run from a shell script. When we run the tool it will ask the user choice to add or delete. When user enter the choice it will then ask how many units he want to delete or add and will add or delete accordingly. Now I want to... (1 Reply)
Discussion started by: saket18@ymail.c
1 Replies

5. Shell Programming and Scripting

Disk Monitoring shell script giving incorrect information

Hi All, OS: Linux 86x64 bits Red Hat Linux I get the email alert for the following when Alert condition is set for 30: /dev/sda1 99M 21M 74M 22% /boot -> Below 30%(Should not get the email alert) Expected output as per E-Mail alert: /dev/sda3 20G ... (2 Replies)
Discussion started by: a1_win
2 Replies

6. Shell Programming and Scripting

Help with script to stop a user giving kill command on a server!!

Hi, I am new to shell scripting and want to create a script with the follwoing description: I want to restrict the users from giving a kill command on a unix server. The server have a restricted logins with login id and passwords. I want a script that will find out if a user has given a... (9 Replies)
Discussion started by: shell_scripting
9 Replies

7. Shell Programming and Scripting

giving input to a python wch has been called frm shell script....urgent

i'm calling a python script from shell script. the python needs Y as an input everytime. how can i giv it thru shell script. I tried below code for arg in `cat erd_gen_list.lst` do generateErdSql.py -S $arg << Y done This is giving me err : `<<' unmatched pls help. (1 Reply)
Discussion started by: vini
1 Replies

8. Shell Programming and Scripting

Help in Shell scripting to modify the User Creation script in oracle database.

Hi, I have several users to create on my test Oracle database taking the scripts from the Production Oracle database. I have a separate text file where I have user-id and passwords maintained. I need help in writing a shell script to go thru the user creation scripts and replace VALUES... (1 Reply)
Discussion started by: rparavastu
1 Replies

9. Shell Programming and Scripting

mv command is giving error in shell script

Hi, In my shell script when I am using mv command using shell variables it is giving me error of syntax. Following is the shell script: file_edifice="*.txt" fquote="'" fdquote=\" for file in $file_edifice do file_name=$fquote$file$fquote tofile_name=`date... (5 Replies)
Discussion started by: gammit
5 Replies
Login or Register to Ask a Question