xbox360dp
asked on
Help with a Script that will rename a file when it's not longer being written to
Gurus,
I need a script that will rename a file when it's not longer being written to.
Step 1: Check and make sure the file isn't being written to.
Step 2: Once file isn't being written to , rename all files in /opt/LAS/tranfer/export/.* to .complete
Any help would be greatly appreciated.
I need a script that will rename a file when it's not longer being written to.
Step 1: Check and make sure the file isn't being written to.
Step 2: Once file isn't being written to , rename all files in /opt/LAS/tranfer/export/.*
Any help would be greatly appreciated.
ASKER
Hi Arnold,
I would like the file to be renamed when there is no more data written. Could you give me an example?
I would like the file to be renamed when there is no more data written. Could you give me an example?
Cron job
Note it does not check whether the file to which it is being renamed does not exist.
Test first.
#!/usr/bin/perl
my $dir='/opt/LAS/transfer/export';
open FILE , "ls $dir |" || die "unable to list contents of $dir:$!\n";
while <FILE> {
chmop();
print "processing $dir/$_\n";
if ( localtime() - stat($dir/$_)[9] >= 90 ) {
#file has it been modified in 90 seconds
rename "$dir/$_", "$dir/$_.complete";
}
}
close(FILE);
Note it does not check whether the file to which it is being renamed does not exist.
Test first.
ASKER
Thanks Arnold!
I tried to test this code in a shell script and got the following errors:
syntax error at ./mod_export.sh line 7, near "while <FILE>"
syntax error at ./mod_export.sh line 10, near ")["
Execution of ./mod_export.sh aborted due to compilation errors.
I tried to test this code in a shell script and got the following errors:
syntax error at ./mod_export.sh line 7, near "while <FILE>"
syntax error at ./mod_export.sh line 10, near ")["
Execution of ./mod_export.sh aborted due to compilation errors.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
How long do you want to wait I.e. After a minutes, no more update So?
http://perldoc.perl.org/functions/stat.html
Checking on last modified..
If you need to extract data while it is being written, you can use a white loop with seek, stat, position writeout .......