Advertisement

05.03.2007 at 01:35PM PDT, ID: 22551541
[x]
Attachment Details

Shell script help for file size or file existence with wildcard.

Asked by markgeer in Linux, Shell Scripting

Tags: shell, file, script, size

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 don’t know how to write that second question in a form that the bash shell accepts, and the bash shell doesn’t like my attempt at the first question either.  Can anyone help me write either of these statements (or a better alternative) so the script doesn’t 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 don’t 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 won’t 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_process.txt ]
  then
    echo "In-process file found, doing nothing"; exit
fi
echo "Creating in-process file..."
touch /var/ora_in/icaras/in_process.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/icaras_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_process.txt
#fi
exitStart Free Trial
[+][-]05.03.2007 at 01:42PM PDT, ID: 19026747

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Linux, Shell Scripting
Tags: shell, file, script, size
Sign Up Now!
Solution Provided By: amit_g
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.03.2007 at 02:09PM PDT, ID: 19026951

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.03.2007 at 02:11PM PDT, ID: 19026969

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.04.2007 at 06:22AM PDT, ID: 19030533

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.04.2007 at 11:56AM PDT, ID: 19033193

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32