0

Instead of giving password, how can I hide the password in the shell script

#!/bin/bash

sqlplus -S -L USERNAME/PASSWORD@"SERVICE_NAME" <<EOF
set feedback off trimspool on

SELECT * FROM TABLE;

spool off;
EXIT
EOF
3
  • Please format your code properly. Commented Nov 5, 2015 at 3:57
  • It violates just about every sane rule against disclosing passwords to consider placing a password in a shell script. That said, the general approach is to include the credentials in a separate file that is only readable by the user who the script runs as and to source the credentials file from a location where no-one but the user has access. That is not a way to do it completely safe, It is just the safest way to do something unsafe the most safely. Commented Nov 5, 2015 at 4:01
  • More suitable for security.stackexchange.com Commented Nov 5, 2015 at 4:05

1 Answer 1

1

This is how I do it:

echo -n "Enter password: "
read -s passwd
echo

sqlplus -s -S << EOF
  USERNAME/${passwd}@"SERVICE_NAME"

  select something from dual;

  exit;
EOF

A neat side effect of this is that the password is also hidden from the OS using ps -efx.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.