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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if a file whether a file is in use or not 1

Status
Not open for further replies.
Jul 28, 2004
726
BE
Hi all,

I've got the following problem.
Users are delivering files (jpg's ) on to our ftp.A program is monitoring the folder, and whenever a new file arrives, the file is being processed.But the file must be there completely before it can be processed.Is there any command that can check whether a file has a status "opened"? I've looked at fuser and lsof, but I can't quite find what i'm looking for.

thx in advance

greetz,

R.
 
NAME
fuser - identify processes using a file or file structure

SYNOPSIS
/usr/sbin/fuser [ - [c | f ] ku ] files [ [ - [c | f
] ku ] files ] ...

DESCRIPTION
fuser displays the process IDs of the processes that are
using the files specified as arguments.

fuser will print the PIDs of processes using the file OR no PIDs if file is "complete".

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Checking that an ftp is complete has always been complex. I've never found a solution such as you propose. One solution I've seen for zip files is to use a loop such as
Code:
while ! unzip -t $FILE
do
  sleep 5
done
however I don't know of a similar test for jpg's.

There are two posible solutions I have used.
1) request a file called finished.flg after the transfer. You can then test for that file knowing the jpg transfer has completed. I've used this very succesfully but it depends on the sender knowing to send the finished.flg after the jpg. This is fine for automated processes but far to comples for somethin involving users. As such this does not seem to fit your case.
2) Check file size.
Code:
FS=0
NEW_FS=1
while [ $NEW_FS -gt $FS ]
do
  sleep 10
  FS=$NEW_FS
  NEW_FS=$(ls -l $FILE | awk '{print $5}')
done
This relies on the file size growing every ten seconds until the transfer is complete. It's very Heath-Robinson but I've seen it work pretty robustly with some tuning of the sleep parameter.

Columb Healy
 
Does fuser work with a file being accessed externally by ftp from another system?

Alex
 
it's the local ftp SERVER that will have the file under "control".

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
One solution I've seen is to send a small (even empty) dummy file after the 'proper' one, and if a test for it's existence succeeds, you can be sure that the original is complete.
 
Having said in my earlier post that I'd never seen the fuser solution work I tried it again after reading Vlad's post. The code was
Code:
while [ -n "$(fuser testfile 2>/dev/null)" ]
do
echo waiting
sleep 1
done
and I ccan confirm that it works fine on AIX 5.1

Thanks Vlad - a star for you.

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top