loop on all db for generate a file containing all db options

Hello,

I try to loop on all db for generate a file containing all db options, only one line is generated on $WorkFileoptions.
How can I do it ?
# Get list db on table db

sqlplus -s /nolog << eof | grep -w 'AAAA' | awk '{ print $1"_"$2".world" }' > $DbList
        connect tool/tool@TOOL
        set line 400
        select HOSTNAME,DBNAME, 'AAAA' from LIST_DB ;
eof

for db in `cat $DbList`
do
      sqlplus -s tooldb/tooldb@$db @Checkoptions > $WorkFileoptions

                   

done

Thanks
bibi92Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
A single redirect "> $WorkFileoptions" does an "open truncate".

A double redirect "> $WorkFileoptions" does an open append.

You are overwriting the file in every loop.
slightwv (䄆 Netminder) Commented:
Try this:
...
#clear out the file
echo > $WorkFileoptions
for db in `cat $DbList`
 do
       sqlplus -s tooldb/tooldb@$db @Checkoptions >> $WorkFileoptions

                     

 done
bibi92Author Commented:
Hello,

Thanks, but I have only the result for the first db.
johnsoneSenior Oracle DBACommented:
Have you checked the file to see that there is more than one line in the $DbList file?

Also, you are doing a lot of work to get the information into the file.  This should be much better.

sqlplus -s /nolog << eof  > $DbList
        connect tool/tool@TOOL
        set line 400 feed off echo off trimspool on pause off pages 0
        select HOSTNAME|| '_' || DBNAME || '.world' from LIST_DB ;
eof

echo "" > $WorkFileoptions
for db in `cat $DbList`
do
      sqlplus -s tooldb/tooldb@$db @Checkoptions >> $WorkFileoptions
done

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.