Python or perl or ruby script for automate file processing -help

Hi All ,

Im looking for a python or perl or ruby script with automate file processing

I have a folder where files drops in unique name continously from webserver ( depend on user upload ) as

Example : Folder contain

file1.cap
file2.cap
.
.
.
Filen.cap

I need scirpt to take new file dropped in that folder and proccess this command in termial

/opt/svr/run.sh -f /Path=/opt/filedropfolder/filen.cap /log=/opt/svr/log/filen.log

Note : (filen.cap and filen.log need to change according to file drop)

Thanks in advance
Sudhagar RajaramanLotus Notes AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gelonidaCommented:
after the command has been run for the file.
Will  the file be deleted from the folder?

In other words how do you know whether a file was already treated or not?
The answer to this question impacts the correct answer / best solution.

I'd suggest a solution using python and the library watchdog if you can install it.
watchdog can watch a diretory for changes and launch actions.
you could use subprocess.Popen() to call the command you'd like to execute.
0
gelonidaCommented:
Another important question:
Can I be sure, that the files, that are in this folder are always complete?

Or could it happen, that if a file is uploaded slowly I would encounter an incomplete file.
How would your commands react if they receive an incomplete file.
Some web frameworks avoid the above mentioned problem by uploading to a temp directory and moving only to the destination folder when the file is completely uploaded.
0
wilcoxonCommented:
Can the files be deleted after processing?
Is it possible that files can be seen before they are complete?  If so, is there a way to tell if/when they are complete?  Can you change the upload process to avoid this issue?
Will the files always be dropped in numeric order?  Do the files have to be processed in order?

Assuming files can not be removed, it's not possible to encounter partial files, and files must be in order, this should do what you want:
use strict;
use warnings;
# config
my $dir = '/opt/filedropfolder';
my $sleep = 10;
# end config
my $num = shift;
if ($num =~ m{^file(\d+)\.cap$}) {
    $num = $1;
} elsif ($num !~ m{^\d+$}) {
    die "invalid start specified - must be fileX.cap or number\n";
}
$num = 1 unless $num;
print "starting from $num\n";
while (1) {
    if (-f "$dir/file$num.cap") {
        system('/opt/svr/run.sh', '-f', "/Path=$dir/file$num.cap", "/log=/opt/svr/log/file$num.log")
            or die "/opt/svr/run.sh failed for file$num.cap: $?";
        $num++;
    }
    sleep $sleep;
}

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Duncan RoeSoftware DeveloperCommented:
Do the files appear strictly in sequence? I'm wondering if, for instance, file3 exists then can we be sure file2 is complete? (but not necessarily file3, if that is the highest number).
Also, under what condition do the numbers reset? (if they ever do)
0
Suhas .QA ManagerCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: wilcoxon (https:#a40902277)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

suhasbharadwaj
Experts-Exchange Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.