I'm creating a bash script to automate a process to create an Oracle database. Basically I want to invoke dbca
. I already found two ways to do it but I still did not like those solutions. I was just wondering if has a better way to do it.
First I already have the sys_password defined on my script
read -p -s "SYS Password: " sys_password
The simplest way is to create a temporary file with the password and pass it via STDIN
.
echo $sys_password > /tmp/file_pwd.txt
echo $sys_password >> /tmp/file_pwd.txt
echo "" >> /tmp/file_pwd.txt
dbca -silent -createDatabase -responseFile /assets/dbca.rsp < /tmp/file_pwd.txt
However, this approach has a security issue because I'm creating a physical file with a sensitive information in the filesystem, even after removed in somehow it can be recovered.
So, the best solution that I could imagine was using the heredocs and pass it via pipe to dbca
.
cat <<EOF | dbca -silent -createDatabase -responseFile /assets/dbca.rsp
${sys_password}
${sys_password}
EOF
I have tried echo
and printf
combined with pipe but it did not produce the same result, anyway, it does not work. Bellow is the code not working:
printf "${sys_password}\n${sys_password}\n" | \
dbca -silent -createDatabase -responseFile /assets/dbca.rsp
I would like to know if there is another way to send the printf
or echo
output to dbca
STDIN
in jut one line