0

I am writing a shell script in Jenkins that logs into a database and runs an sql file. All of the commands are logged to the console, so if I use the simple login method for sqlplus (sqlplus -s $USERNAME/$PASSWORD@connectionstring), the password gets logged, which isn't ideal.

This works:

sqlplus -S ${USERNAME}/${PASSWORD}@connectionstring @sql_update.sql

but the logging on Jenkins shows the command once the values have been substituted:

 + sqlplus user123/pass123@connectionstring @sql_update.sql

To avoid having the password logged, I am trying to use the sqlplus login method where you just provide the username and then get asked to input the password. I have tried the following, but I am getting ORA-01-17: invalid username/password; logon denied

sqlplus -s ${USERNAME}@\"connectionstring\" <<EOF
${PASSWORD}
sql_update.sql
exit
EOF

Is there something obviously wrong with this?

It's worth noting that simply disabling the console logging isn't an option, as we need it for other things in the script.

Also, the difference between this question and Connect to sqlplus in a shell script and run SQL scripts is that I am asking about providing the password separately.

EDIT I managed to partially resolve the issue thanks to Echo off in Jenkins Console Output. My script now contains set +xbefore the commands are run, which hides the commands. However, I'd still like to know what was wrong with the above, so am leaving this question open for now.

Ben Green
  • 3,623
  • 2
  • 26
  • 43
  • Shouldn't it be `sqlplus -s "$USERNAME/$PASSWORD@connectionstring"` ? – user1934428 Jul 30 '18 at 09:45
  • @user1934428 You can connect in different ways: https://docs.oracle.com/cd/B14117_01/server.101/b12170/qstart.htm If I do `sqlplus -s "$USERNAME/$PASSWORD@connectionstring"` then the command is logged to the console. – Ben Green Jul 30 '18 at 09:49
  • 1
    Just a wild guess: If you don't supply the password on the command line, I don't think that you can simply provide it via STDIN redirection to a HERE-document. Isn't it the case that sqlplus prompts you for the password? If this is so, it might be necessary to use a tool like [expect](https://en.wikipedia.org/wiki/Expect) to provide the password. – user1934428 Jul 30 '18 at 15:35

0 Answers0