Passing string from SQL to a BASH script

OS Solaris 10,
DB oracle 10g

Hello,
We currently have a BASH script that runs and moves image files from a remote server to the local db server. A snippet of the code shows that we are picking up all Images that are 'mtime -1'

some code...
for file in `ssh user@10.200.200.10 'find /u01/bea/madeup/Images -name "*.jpeg" -mtime -1'`
do
scp user@10.200.200.10:${file} /oraworking/madeup/images/orig/
done
...more code

It's simple and it works.

Now, due to development requirements we need a way of picking up those images from different directories within the base directory of /u01/bea/madeup/Images. The plan is to have an 'index' table that will hold the location (path and filename) of the image file and it is this that I would like to read from the table and somehow use in place of the hard coded file path above.
Can I Just do something like this example: (This may work with some tweaking, but it gives you an idea of what i am trying to achieve).

for file in `ssh user@10.200.200.10 'find /oracle/product/db/10gR2/bin/sqlplus -s /nolog  <<EOF  #Find is just going to try and find something in '/oracle/product/db/10gR2/bin/sqlplus' so this is wrong!

conn / as sysdba

set heading off
set feedback off
set pagesize 0
set linesize 30000
set trimout on
SELECT f.file_path||'/'||f.file_name
FROM fileupload f
INNER JOIN imagelog i
ON f.id = i.fileupload_id;'

EOF`

do
if [ -f ${file} ]
then
        echo "Skipping $file file..."
continue
fi

scp user@10.200.200.10:${file} /oraworking/madeup/images/orig/

done
...more code

Thanks in Advance,

Jonathan

Hi

u can first try running the sql and spool required fields or coulmn/s to afile and then pass the list to find command

for i in `cat list` do ssh user@10.200.200.10  "find path -name "$i" >> file
done

then u can use the list in the file named file to scp or sftp

Thanks for the advice zozoo. I tried to write the output to a file but had issues with the text wrapping or putting the pathname and the filename on different lines likely due to something I was or was not doing. Anyway I went back to my code and tweaked it to the following:

for file in `ssh user@10.200.200.10 find

${ORACLE_HOME}/bin/sqlplus -s /nolog  <<EOF

conn user/user
SET WRAP OFF
SET HEADING OFF

SELECT f.file_path||'/'||f.file_name
FROM fileupload_index@tardev1 f
INNER JOIN imagelog@tardev1 i
ON f.id = i.fileupload_id
WHERE f.file_name IS NOT NULL;

EOF
-type f`

do
scp user@10.200.200.10:${file} /oraworking/madeup/images/orig/
done

Despite the Crudity, this seems to do what I want it to do. Full test coming up...

Thanks again

OK so that worked and then didn't, and then did and then didn't!
So I am using zozoo's method which works a treat (thank you!).

some code...

IMG_OUT=`${ORACLE_HOME}/bin/sqlplus -s /nolog  <<EOF

conn user/password

set feed off
set head off
set pages 0
@getimages
EOF`

echo "${IMG_OUT}" >> list

for i in `cat list`
do scp  csuser@10.202.200.11:${i} /oraworking/madeup/images/orig/
done

...more code

Thanks again for your help zozoo!

Now how does one close a thread!?