Q

Running a script without user's password to Oracle database

Is there any way to run a script .sh (Unix) or .bat (Windows) automatically or manually without including the password of the user that connects to the database or entering manually that password?

Hello Brian,
Is there any way to run a script .sh (Unix) or .bat (Windows) automatically or manually without including the password of the user that connects to the database or entering manually that password? That is, perhaps reading directly from any file of the database or something like this? Thanks in advance.

In my shell scripts, I can code something similar to the following:

sqlplus /nolog <<EOF
connect username/password
@script
EOF

The above will invoke SQL*Plus and pass everything up until the EOF string to SQL*Plus. The big problem with the above is that if you have multiple shell scripts, then it can be a pain to change the password. So I often prefer to store the password as the only word on the only line in a file (I'll call that file 'pass'). Then I invoke SQL*Plus in my shell script as follows:

sqlplus username @/dir/my_script.sql < /dir/pass

When the above is run, SQL*Plus will start and the password will be passed from the file. If you change your password, you only need to update this file and all of your scripts will work. If you do choose this method, make sure you do "chmod 600" on this file so that only your user can read the file's contents.

This was first published in July 2007

Dig deeper on Oracle database design and architecture

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close