Sponsored Content
Top Forums Shell Programming and Scripting A script to scan a directory for XML files, Post 302381090 by apacheuk on Friday 18th of December 2009 05:50:37 AM
Old 12-18-2009
Yeah it does have to be in time order, thanks for the replies

Code:
if [ ! -z "$XMLFILES" ]; then
# processing loop here
fi



---------- Post updated 18th Dec 2009 at 10:50 AM ---------- Previous update was 17th Dec 2009 at 11:48 AM ----------

OK, so I've finished my script and it runs successfully Smilie

I'll be honest this is the first unix/linux script I've coded before, would it be possible for you kind people to give it the once over and give me some feedback??? It's very simplistic and I could probably have found a script on the net somewhere to do the same thing, but I find the best way to learn is too role your sleeves up and get stuck in

It's purpose is when called is to process all the xml files in a directory and then move them elsewhere based on the result of an Oracle stored procedure.

Thanks

Code:
#!/bin/sh
# setup some constants
#      DIR_PATH is the path to the xml files to be processed
#      PROCESSED_PATH is the path to xml files that have been successfully processed
#      ERRORED_PATH is the path to xml files that failed processing
DIR_PATH='/home/f450242/xml'
PROCESSED_PATH='/home/f450242/xml/processed'
ERRORED_PATH='/home/f450242/xml/errors'
# run timestamp
DT=`date`
echo " ***** BEGIN PROCESS ***** "
# first make sure our paths are all accessible
if [ ! -d $DIR_PATH ]
then
  echo "$DT:> $DIR_PATH cannot be found"
  exit
fi
# check to see if there are any xml files to process
# no point continuing if there arent any!
if [ test ! -e $DIR_PATH/*.xml ]
then
  echo "$DT:> no xml files found"
  exit
fi
if [ ! -d $PROCESSED_PATH ]
then
  echo "$DT:> $PROCESSED_PATH cannot be found"
  exit
fi
if [ ! -d $ERRORED_PATH ]
then
  echo "$DT:> $ERRORED_PATH cannot be found"
  exit
fi
# check to make sure we can connect to SQLPLUS
# exit and report if we can't
SQLUP=`sqlplus -s xxxxxx@dev/xxxxxxx<<EOF
       exit
       EOF`
# $? variable is used to hold the exit status of the previous command
# 0 success, anything else is an error
if [ $? -ne 0 ]
then
  echo "$DT:> SQLPLUS not available"
  exit
fi
# check for the existence of our lock_file
# if found it means the process is still running
# so we need to exit
if [ -f $DIR_PATH/lock_file ]
then
  echo "$DT:> lock_file found, exiting"
  exit
fi
# about to start our process so create our lock_file
touch lock_file
# store the list of files to process
XML_FILES=`ls -rt $DIR_PATH/*.xml`
# loop through each file and call our Oracle routine to process the file
for f in $XML_FILES
do
  SUCCESS=`sqlplus -s xxxxxx@dev/xxxxxxx << EOF
           set serveroutput on
           declare
             vout varchar2(10);
           begin
             test_proc(1,vout);
             dbms_output.put_line(vout);
           end;
           /
           commit;
           exit;
           EOF`
  CHECK=`echo $SUCCESS | awk '{print $1}'`
  if [ $CHECK = "TRUE" ]
  then
    mv $f $PROCESSED_PATH
  else
    mv $f $ERRORED_PATH
  fi
done
rm lock_file
echo " ***** END PROCESS ***** "

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script to scan through files

Dear perl gurus, I plan to create a script that will scan through a logfile line by line. And if ever a certain line meets the below conditions, it will alert me via email. --> a) Position 10 to 13 = "ABCD" b) And also if the amount specified in position 620-640 is less than the amount in... (1 Reply)
Discussion started by: gholdbhurg
1 Replies

2. Shell Programming and Scripting

Script to Scan proclog files

i need to create a shell script, which will go into a directory , and scan the files in it for defined errors, there will be around 10 files in the directory. (3 Replies)
Discussion started by: deeprajn95
3 Replies

3. Shell Programming and Scripting

scan directory

The script should _scan a specific directory _If a file name is like one provided, then run the command to send the file via CFT The name should be picked from a list. The current list is : ... (11 Replies)
Discussion started by: fireit
11 Replies

4. Shell Programming and Scripting

Scan directory and sub directories

I am really stuck on a issue and have not been able to find a solution. With the code below I need to not only scan the current directory which as you can see below is... /lcl/sit/apps/Tivoli/ But I also want it to scan all sub directories it finds under Tivoli as well for the same thing... (2 Replies)
Discussion started by: LRoberts
2 Replies

5. Shell Programming and Scripting

Generating an xml having information related to files in the directory

Hi all, Have to generate an xml having information related to files in the directory Suppose i have file file1.xml (datafile) file2.xml (datafile) file3.xml (metafile) Now i need to generate an xml in the format >> <?xml version="1.0" encoding="UTF-8"?> <AuditFile Version="2.0">... (8 Replies)
Discussion started by: abhinav192
8 Replies

6. Shell Programming and Scripting

Script which removes files from the first directory if there is a file in the second directory

Script must removes files from the first directory if there is a file with same name in the second directory Script passed to the two directories, it lies with them in one directory: sh script_name dir1 dir2 This is my version, but it does not work :wall: set - $2/* for i do set -... (6 Replies)
Discussion started by: SLAMUL
6 Replies

7. UNIX for Dummies Questions & Answers

Need help how to create a file (xml) list all files from directory

I have more than 10K songs in two directories on a hard drive. I would like to create a file list all of files name then change to .xml extension to upload to iPhone so I have a Karaoke list on my iPhone. I need your help to create a file by using command in Linux. Files names: 0001 More... (4 Replies)
Discussion started by: ggcc
4 Replies

8. Shell Programming and Scripting

Copying xml files to a chosen directory

I want to determine if there's any xml files exist & if so copy each xml to that directory. Is my code correct for doing that? I can't test my script yet. Somebody please explain it to me please? if ]; then #print "No Status type XML files received from server in $DIRECTORY" else for... (2 Replies)
Discussion started by: emc^24sho
2 Replies

9. Shell Programming and Scripting

Moving Files one directory to another directory shell script

Hi, Could you please assist how to move the gz files which are older than the 90 days from one folder to another folder ,before that it need to check the file system named "nfs" if size is less than 90 or not. If size is above 90 then it shouldn't perform file move and exit the script throwing... (4 Replies)
Discussion started by: venkat918
4 Replies

10. Shell Programming and Scripting

Create automated scan of specific directory using bash

I am trying to use bash to automate the scan of a specific directory using clamav. Having this in place is a network requirement. The below is an attempt to: 1. count the extensions (.txt, .jpeg) in a directory and write them to a virus-scan.log (section in bold) 2. scan each folder in the... (6 Replies)
Discussion started by: cmccabe
6 Replies
XML_PP(1)						User Contributed Perl Documentation						 XML_PP(1)

NAME
xml_pp - xml pretty-printer SYNOPSYS
xml_pp [options] [<files>] DESCRIPTION
XML pretty printer using XML::Twig OPTIONS
-i[<extension>] edits the file(s) in place, if an extension is provided (no space between "-i" and the extension) then the original file is backed-up with that extension The rules for the extension are the same as Perl's (see perldoc perlrun): if the extension includes no "*" then it is appended to the original file name, If the extension does contain one or more "*" characters, then each "*" is replaced with the current filename. -s <style> the style to use for pretty printing: none, nsgmls, nice, indented, record, or record_c (see XML::Twig docs for the exact description of those styles), 'indented' by default -p <tag(s)> preserves white spaces in tags. You can use several "-p" options or quote the tags if you need more than one -e <encoding> use XML::Twig output_encoding (based on Text::Iconv or Unicode::Map8 and Unicode::String) to set the output encoding. By default the original encoding is preserved. If this option is used the XML declaration is updated (and created if there was none). Make sure that the encoding is supported by the parser you use if you want to be able to process the pretty_printed file (XML::Parser does not support 'latin1' for example, you have to use 'iso-8859-1') -l loads the documents in memory instead of outputing them as they are being parsed. This prevents a bug (see BUGS) but uses more memory -f <file> read the list of files to process from <file>, one per line -v verbose (list the current file being processed) -- stop argument processing (to process files that start with -) -h display help EXAMPLES
xml_pp foo.xml > foo_pp.xml # pretty print foo.xml xml_pp < foo.xml > foo_pp.xml # pretty print from standard input xml_pp -v -i.bak *.xml # pretty print .xml files, with backups xml_pp -v -i'orig_*' *.xml # backups are named orig_<filename> xml_pp -i -p pre foo.xhtml # preserve spaces in pre tags xml_pp -i.bak -p 'pre code' foo.xml # preserve spaces in pre and code tags xml_pp -i.bak -p pre -p code foo.xml # same xml_pp -i -s record mydb_export.xml # pretty print using the record style xml_pp -e utf8 -i foo.xml # output will be in utf8 xml_pp -e iso-8859-1 -i foo.xml # output will be in iso-8859-1 xml_pp -v -i.bak -f lof # pretty print in place files from lof xml_pp -- -i.xml # pretty print the -i.xml file xml_pp -l foo.xml # loads the entire file in memory # before pretty printing it xml_pp -h # display help BUGS
Elements with mixed content that start with an embedded element get an extra <elt><b>b</b>toto<b>bold</b></elt> will be output as <elt> <b>b</b>toto<b>bold</b></elt> Using the "-l" option solves this bug (but uses more memory) TODO
update XML::Twig to use Encode with perl 5.8.0 AUTHOR
Michel Rodriguez <mirod@xmltwig.com> perl v5.16.3 2012-11-14 XML_PP(1)
All times are GMT -4. The time now is 03:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy