Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move a file only if it's complete

Status
Not open for further replies.

twentyseven

IS-IT--Management
Oct 21, 2002
1
FR
Hello,

I'm receiving files on my FTP server on unix and I'd like to move them only when they are complete.
Does it exit a mean using the move command (or other) to do it ?

Thanks,

Twentyseven.
 
hi,
I don't know an "exact" method.
(Only ftp server coulda launch a script to move file ).

When I have had this problem, from the client, in the
same script, I send a OK file, (same name of data-file
whit different extension.

123456789.dat
123456789.ok

If your procedure is activated by cron, or manually,
check the presence of ok file, then move.
To be more precise, in my ok file, I put, inside it, the
size of data-file, to obtain a more sure action

bye
 
you could use 'fuser' and see if file is 'locked/used'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
man fuser

Maintenance Commands fuser(1M)



NAME
fuser - identify processes using a file or file structure



vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
fuser does the trick for me, the command will list the files in use:

cd /your/upload_dir
fuser * 2>&1 | awk '$2 != &quot;&quot; { print $1 }' | cut -d: -f1

I use it in this format, not the best, but it works:
FILESINUSE=`fuser * 2>&1 | awk '$2 != &quot;&quot; { print $1 }' | cut -d: -f1`
if [[ -n $FILESINUSE ]];
then
echo &quot;No files available&quot;
exit
else
echo &quot;Files exist, moving...&quot;
mv * /somedir/
fi

You could take it a bit further and do a for loop for each value of FILESINUSE. I opted not too, I rather check later (30 seconds on) and only move files when all files are available.



IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
MS Certified Windblows Rebooter
 
[tt]
I agree with using fuser, but in relation to that code from
aixmurderer, from the time the fuser was done until the
time he execute the mv *, new files may have started
writing to the directory and may still be open.

How about... (rough pseudo code, may be errors).

------------------------------------------------------------
for file in *
do
FILESINUSE=`fuser $file 2>&1 | awk '$2 != &quot;&quot; { print $1 }' | cut -d: -f1`
if [[ -n $FILESINUSE ]]
then
echo &quot;$file not available&quot;
else
echo &quot;moving $file...&quot;
mv $i /somedir/
fi
done
------------------------------------------------------------

or...

FILELIST=`ls *`

And work on every filename on that list, then when
confirmed...

mv $FILELIST destdir/

If you're worried about integrity issues then these would
seem like basic steps to ensure it.
[/tt]
 
write a footer on the file bedore ftp.
then check during/after ftp for this footer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top