Ask the Expert

Running a script without user's password to Oracle database

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.

    Requires Free Membership to View

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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: