Solved

How do I run an SQLPlus script to perform several Administration functions?

Posted on 2008-06-18
5
1,477 Views
Last Modified: 2012-05-05
HI,

     I have a few administrative commands I need to run against 3 different Oracle databases on the same instance. What is the syntax to connect to each db and execute commands via batch file?

connect to Database A
SQL>Revoke execute on UTL_FILE from Public;
SQL>Revoke execute on UTL_TCP from Public;
SQL>Alter user CTXSYS identified by Test12 account lock password expire;

connect to Database B
SQL>Revoke execute on UTL_FILE from Public;
SQL>Revoke execute on UTL_TCP from Public;
SQL>Alter user CTXSYS identified by Test12 account lock password expire;

Could you recommend a good link\book for running batch files in SQLPlus?

Thank You, Missymadi

0
Comment
Question by:missymadi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:ajexpert
ID: 21817010
Here is the syntax

sqlplus /nolog <uid>/<pwd>@<instance> @<scriptpath>
0
 
LVL 3

Expert Comment

by:dalebetts
ID: 21817081
Create two files, one named admina.sql with the following:

Revoke execute on UTL_FILE from Public;
Revoke execute on UTL_TCP from Public;
Alter user CTXSYS identified by Test12 account lock password expire;

and one named adminb.sql with:

Revoke execute on UTL_FILE from Public;
Revoke execute on UTL_TCP from Public;
Alter user CTXSYS identified by Test12 account lock password expire;

And then to execute from the SQL prompt type:

@admina or @adminb

You have to ensure that files are in your current directory as you load sqlplus otherwise you have to supply the full path name for example if the files are store in C:\scripts

SQL> @C:\scripts\admina

You don't have to put the .sql suffix on the end of the filename when executing, it will work both ways.

Regards
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 21817101
dalebetts:
I think missymadi is asking to execute from Batch File
0
 
LVL 23

Expert Comment

by:David
ID: 21818695
Extending AJ's contribution:
#!/usr/bin/sh
sqlplus /nolog <uid>/<pwd>@<instanceA> <<EOF
Revoke execute on UTL_FILE from Public
/
Revoke execute on UTL_TCP from Public
/
Alter user CTXSYS identified by Test12 account lock password expire
/
EOF

And repeat as needed.  You might want to create a new question and learn how to pass the SID name as an argument to the batch file.
0
 
LVL 3

Accepted Solution

by:
dalebetts earned 125 total points
ID: 21821355
windows batch file?

The above would be no good in Windows environment. For windows just create test.bat, with:

set ORACLE_SID=<sid>
sqlplus username/password
Revoke execute on UTL_FILE from Public
/
Revoke execute on UTL_TCP from Public
/
Alter user CTXSYS identified by Test12 account lock password expire
/
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question