This shell script works, but is inefficient, especially in the last 12 lines where I have to call the Oracle sqlplus utility (which runs the *.sql file to: log in to Oracle and run a stored procedure which can read the text file that "find" just created) to see if there are any files for Oracle to process or not. I think the shell script should be able to determine that for me and skip the call to Oracle when there are no new files found.
I think a good option is some kind of if check in Linux at that point (something like the one I have commented out, which bash doesn't like). It could either be:
1. do any files like: CARSEQ_XML*.xml exist in this directory?
or:
2. is the file: filelist.txt larger than 0 bytes?
I dont know how to write that second question in a form that the bash shell accepts, and the bash shell doesnt like my attempt at the first question either. Can anyone help me write either of these statements (or a better alternative) so the script doesnt have to call sqlplus if there are no files found to process? Another option might be to set a variable in the middle section if the mv succeeds, then evaluate that variable later, but I dont know how to do that either in a shell script.
If you have any other thoughts, suggestions or questions about this shell script, just let me know, you wont hurt my feelings. I'm an Oracle DBA who is unfortunately forced to be a Linux sys admin as well, but I have no UNIX experience, and limited Linux experience. (Most of my O/S experience is on: VMS, Netware and DOS/Windows.)
(Yes, I know the "echo" commands can be removed after I get this working as intended.)
#!/bin/bash
# Start by looking for "in-process" file, and do nothing if found
if [ -e /var/ora_in/icaras/in_proc
ess.txt ]
then
echo "In-process file found, doing nothing"; exit
fi
echo "Creating in-process file..."
touch /var/ora_in/icaras/in_proc
ess.txt
cd /znas1/icaras_to_ora
for fn in CARSEQ_XML*.xml; do
if mv "$fn" "/var/ora_in/icaras"; then
echo "file moved successfully"
else
echo "file locked, or not found!"
fi
done
#if [ -e /var/ora_in/icaras/CARSEQ_
XML*.xml ]
# then
echo "File(s) found, building list for Oracle"
cd /var/ora_in/icaras
find . -name "CARSEQ_XML*.xml" -maxdepth 1 -print > filelist.txt
sqlplus @/home/oracle2/scripts/ica
ras_orders
.sql
# move the processed files to the "done" directory:
mv CARSEQ_XML* ./done
# Now, remove the "in_process" file
/bin/rm /var/ora_in/icaras/in_proc
ess.txt
#fi
exit
Start Free Trial