Running SQLPLUS - A simple example...

The following script runs a simple query and appends the result to a file.

Query.sql:

SET FEEDBACK OFF
SET HEADING OFF
SET PAGESIZE 0
SET SERVEROUTPUT ON
SELECT COUNT(*) FROM v$SESSION;
EXIT

runQuery.sh:

#!/bin/sh
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

sqlplus -S perfstat/perfstat @query.sql > output.txt