i want to move files from A dir to B dir, say eg: mv *memo*.txt /scripts/memo/
but while doing this new files are being uploaded by users, i dont want files which are being uploaded 5 to 10 min ago. other wise even files which are being currently uploaded will get moved to /scripts/memo.
Save a list of the directory just before the copy, then loop through that list.
If your still having trouble, post the script you have tried
in /abc/jrd/
users are continuously uploading files memo*.txt
i have created a memo.sh file in that i have written
cd /abc/jrd/
mv memo*.txt /scripts/memo
while files are being moved to this /scripts/memo users who are uploading new file are not getting fully copied i this path i want that there should be delay for 5 to 10 min of current file transfer and rest file should be move to /scripts/memo
does it work?
find . -name "memo*.txt" -mmin +10 |xargs -i mv {} /yourTarget/
i am getting this error in putty
find: bad option -mmin
What if the file is several GB large and it will take more than 10 minutes?
I suggest checking whether the file is being accessed with 'lsof'. Something like this:
for i in memo*.txt ; do
if [ ! -z "`lsof $i`" ] ; then
echo "File $i is being accessed. Skipping..."
else
mv $i $target
fi
done
and these files are not in Gb. i just want that when users are uploading these and when i am moving these files through scripts there should be delay of 10 min or half hour. Kindly help
i got this error
memotest.sh[2]: lsof: not found
Set up this script to run every 5 or 10 minutes as you wish:
#!/bin/ksh
for mFile in `find ./*memo*txt ! -newer Flag_File`
do
mv ${mFile} New_Directory
done
touch Flag_File
Good idea, I'd modify it just slightly to avoid the dangerous useless use of backticks and make sure Flag_File already exists.
#!/bin/ksh
[ -f Flag_File ] &&
find ./*memo*txt ! -newer Flag_File |
while read mFile
do
mv ${mFile} New_Directory
done
touch Flag_File