Executing SQL inside a shell script
Running SQL from a shell is really useful. Most of the time I use it to capture data for logs. For example, I have a shell cronned hourly that gets the number of sessions logged in and the size of the development tablespace. I implemented this during registration to monitor the growth of the database and average user sessions.
This example queries for the number of sessions and places it in a variable called numsession:
This example queries for the number of sessions and places it in a variable called numsession:
numsession="`sqlplus -s /nolog<<EOF
connect / as sysdba
set heading off;
set echo off;
set feedback off;
select count(*) from v\\$session where username is not null;
exit;
EOF`"
Comments