shell scripting

Recording query output in a self contained shell script...

General form

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

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.0.0.0/dbhome_1
export ORACLE_SID=orclcdb1
export PATH=$ORACLE_HOME/bin:$PATH

while [ true ]
do
  sqlplus -s / as sysdba  >> output.txt << EOF
SELECT * FROM DUAL;
EXIT
EOF
  sleep 10
done

Session Serialization Example

Quickie script to run dbv on your database...

This script will generate dbv commands into a shell script and then execute the shell script.

run-dbv.sql:

set head off
set lines 200
set feedback off
set define off
spool dbv.sh

select 'dbv file='||name||' blocksize = '||block_size||
' LOGFILE=FILE-'||FILE#||'.LOG' from v$datafile;
spool off

host chmod 755 dbv.sh
spool dbv_results.log
host ./dbv.sh
spool off

Output will be created as separate log files. You can run it and review results like this:

$ sqlplus "/ as sysdba" @run-dbv.sql

Subscribe to shell scripting