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