Rohith Rohith - 24 days ago 7
SQL Question

How to supress the output of .sql script when placed inside bash script

Below is my simple bash script:

#!/bin/bash
cd /app/oracle/client11_2/
connect <<EOF
@/app/oracle/client11_2/testquery.sql
exit;
EOF


Note: testquery.sql contains some "SELECT" queries and also i have used spool to store the content of the queries.

But, when i execute the bash script on the terminal, it produces lot of unwanted output like below:

SQL*Plus: Release 11.2.0.3.0
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options


How to avoid this output..!? I do not want this to be printed on the output screen when i execute the bash script.

Answer

Make the here doc (<<) snippet as:

connect <<EOF >/dev/null
@/app/oracle/client11_2/testquery.sql
exit;
EOF

this sends the STDOUT of the here doc to /dev/null.


You can also do the output redirection at run time, sending the whole STDOUT of the script to /dev/null e.g.:

./script.sh >/dev/null

again this sends the whole STDOUT of the script to /dev/null (YMMV).