LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-11-2008, 02:50 PM   #1
michael.barnes
LQ Newbie
 
Registered: Jan 2007
Location: North Texas
Distribution: SUSE 9, 10; CentOS4,5;Redhat; (K)Ubuntu; Knoppix
Posts: 23

Rep: Reputation: 0
perl- check size to see if file is complete


I'm trying to use perl to manipulate some files in a drop box environment. Everything is fine until someone drops a big (300+MB) file in the dropbox folder. It seems the script attempts to do its thing before the file is entirely copied into the dropbox. I was thinking of checking the file size every few seconds and when it came back three times the same size it could be assumed to be complete and press on. I've been trying to sort out lstat to do this but I can't seem to get my loops set up right. Basically, I want to do this:

glob the folder to an array
foreach each file
file size = $size
wait a few seconds
does file = $size?
repeat until file = $size three times

then continue processing file
go back to array grab next file and do it again.

Is my approach valid?
Any suggestions of perl script segments for each part of this game?

Thanks for helping a noob.
 
Old 02-11-2008, 04:17 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 151Reputation: 151
Do you have any control over the application dropping the files into the directory? We set up a process on a project here where each file being dropped had a zero byte flag file with it.

Basically what happened was this:
- Application writes data file (*.dat) to directory;
- After data file is written, application writes 0 byte flag file (*.flag) to directory.

The application polling the directory looks for the flag files. It's process is simple:
- Poll for flag files;
- Process the data file for each found flag file;
- Delete the data and flag file.

All of which is not much use if you can't control the application dropping the files into the directory...
 
Old 02-13-2008, 06:20 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Gilead's soln is good, used it myself in the past.
Otherwise a simple loop ?
eg
Code:
$cnt=0;
$last_size=0;
$curr_size=0;

for $file ( @file_list )
{
    $last_size = (stat($file))[7];
    while(1)
    {
        sleep(5);
        $curr_size = (stat($file))[7];
        if( $curr_size == $last_size )
        {
            $cnt++;
            if( $cnt >= 3 )
            {
                action_file($file);
                last;
            }
        }
        $last_size = $curr_size;
    }
    $last_size = 0;
    $curr_size = 0;
    $cnt = 0;
}
NB: Untested (!) but you get the idea ...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: Check if file has been created in the last 10 minutes introuble Programming 2 06-02-2006 10:58 AM
is there a way to increase a partition size after the installation is complete? tad@optix Red Hat 6 06-13-2005 06:33 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
SuSE 8.1 ftp complete directory tree size? cav Linux - General 2 04-01-2003 12:44 PM
Need script to check file size. _TK_ Linux - General 1 08-06-2001 08:30 AM


All times are GMT -5. The time now is 06:08 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration