Algorithm to load files efficiently without missing or accidently archiving....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Algorithm to load files efficiently without missing or accidently archiving....
# 1  
Old 02-19-2012
Algorithm to load files efficiently without missing or accidently archiving....

We have a requirement where we get the Delta Files in every one hour and we need to load them into Oracle database every one hour using Powercenter. To efficiently do this we need to build an File management system.
Here is our process:
we get 6 files for 6 tables with a timestamp appended .dat files (employee_021920121033.dat) along with these 6 files we get a .done (hr_021920121033.done) file indicating the 6 six files are ready to be loaded.

Now we need to build a script that will identify that these files are ready to be loaded thereby move them to corresponding source directory and invokes the corresponding workflow that will load these files.

Has anybody worked on this scenario. If so how did you achieve this?
# 2  
Old 02-19-2012
You could try something like this:

Code:
#!/usr/bin/env ksh
trap "rm -f /tmp/PID$$.*; exit" EXIT 2 3 15

incoming_dir=/path/of/incoming/directory

if ! cd $incoming
then
    echo "unable to switch to incoming directory"
    exit 1
fi

wrk_list=/tmp/PID$$.wrk
file_list=/tmp/PID$$.file
while true
do
    delay=300               # default to short delay
    find . -name "*done" >$wrk_list
    while read done_file                # find and process all done files
    do
        base=${done_file%%.*}
        find . -name "*${base##*_}*" >$file_list
        while read file
        do
            echo "put command(s) to load file into db here"
            delay=3600      # did work, sleep longer
        done <$file_list
    done <$wrk_list

    sleep $delay        # wait for (more) work
done

This will check for done files and wait 5 minutes between checks if it doesn't find any to work on. When it does find some work to do, it sleeps for 30 minutes before checking again -- assuming that it will be at least that long before another set of files is available, so there's not a need to check more frequentially immediately after doing some work.

The script will also handle more than one done file, so if the script isn't running when done files come in, it will do all of them that were waiting. If it is important to process the files in order, then you'll need to sort the list of done files accordingly.

BIG NOTE: I didn't test this script at all, so there might be typos, or other issues.

Last edited by agama; 02-19-2012 at 03:55 PM.. Reason: typo
# 3  
Old 02-20-2012
Thank you very much agama..Im gonna give this a try and update you...I will correct the typos...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Efficiently altering and merging files in perl

I have two files fileA HEADER LINE A CommentLine A Content A .... .... .... TAILER AfileB HEADER LINE B CommentLine B Content B .... .... .... TAILER BI want to merge these two files as HEADER LINE A CommentLine A Content A (4 Replies)
Discussion started by: sam05121988
4 Replies

2. Shell Programming and Scripting

Archiving the files

hi, Am trying to acrhive a bunch of files on some ftp site and somehow managed to come out with the below logic. I'm getting "syntax error: unexpected end of file" error. Interestingly this below snipeet works fine if run for the first time but the subsequent runs fail! Anybody has any idea... (3 Replies)
Discussion started by: Amee5
3 Replies

3. Shell Programming and Scripting

Archiving older files

Hello Group, I would request your help to build a shell script in order to find files older than 90 days then create the same directory structure under the second disk (/archive directory) and move the file preserving the same timestamps (ownership, etc). Also keep the log of files moved... (4 Replies)
Discussion started by: csierra
4 Replies

4. UNIX for Dummies Questions & Answers

Archiving the files in a .txt file

HI , I have a file abc.txt, which has some .csv files listed. example. abc.txt 1.csv 2.csv 3.csv 4.csv 5.csv I want to move all the files listed in abc.txt to a archive directory,and zip the moved files. Can anyone help me with the script. Thanks,sai (1 Reply)
Discussion started by: saii
1 Replies

5. Shell Programming and Scripting

Issue while archiving the files

Hi, In our current process we are reading the file, (which is placed by external vendor)from one particular folder and processing those files through ETL(informatica). We are reading these file as " ls -ltr *.txt" Once the process is finish these files are moved to archived script by "mv"... (1 Reply)
Discussion started by: Amey Joshi
1 Replies

6. Shell Programming and Scripting

Archiving the Files in a folder

My requirement is to put all the files from output directory(ATT) to archive directory(archive\) creating a new folder with datetimestamp(20100212_120014) every time it runs. where ${IMF_TARGET_DIR} is my base directory. ${IMF_ARCHIVE_DIR} is my Archive directory... (1 Reply)
Discussion started by: vsmeruga
1 Replies

7. UNIX for Dummies Questions & Answers

Archiving and move files in the same time

Hi All, I have tried so many command but none work like i wanted. I would like archive which i assume it will move the files and archive it somewhere. for example: if i have a folder and files: /home/blah/test /home/blah/hello /home/blah/foo/bar i would like to archive folder... (6 Replies)
Discussion started by: c00kie88
6 Replies

8. Shell Programming and Scripting

Archiving the files

Hi, Suppose I have 2 files of yesterday's. And today I have received 3 files. Before processing anything I want to archieve the 2 files of yesterday's into a different folder. How can this be done? Regards, Sunitha (1 Reply)
Discussion started by: Sunitha_edi82
1 Replies

9. UNIX Desktop Questions & Answers

how to search files efficiently using patterns

hi friens, :) if i need to find files with extension .c++,.C++,.cpp,.Cpp,.CPp,.cPP,.CpP,.cpP,.c,.C wat is the pattern for finding them :confused: (2 Replies)
Discussion started by: arunsubbhian
2 Replies

10. Shell Programming and Scripting

Archiving and moving the files

hi all i have a requirement where in i have to zip all the files with "*.bkp" after 14 days and move the zip files to Archive directory .... i am able to achieve the first functionality but not able to achive the second one ...here is my code find ${LOG_DIR} -name "*.bkp" -mtime +14 | xargs -i... (1 Reply)
Discussion started by: nvuradi
1 Replies
Login or Register to Ask a Question