Running sqlplus for 5 DB in a shell

Hi all,
on AIX 6.1 I want to run the following but for 5 DB. How should I do that ? Using FOR, WHILE ???? How ?


export ORACLE_SID=DB1
sqlplus / as sysdba << EOF
whenever sqlerror exit sql.sqlcode;
whenever oserror exit FAILURE

set define off
set head off
set feedback off
set echo off
set pagesize 0
set pages 0
set linesize 200
set timing off

spool DB1.txt
select * from v$instance;

EOF

I have DB1, DB2, DB3, DB4,DB5.

Thank you.

Yes a simple for-loop, or put it into a function and call it 5 times with the DB name as an argument.

for DB in DB1 DB2 etc; do
  ORACLE_SID=$DB
  sqlplus / as sysdba << EOF
  ...
  spool $DB
  ...
EOF
done