Home » Infrastructure » Unix » Getting File Status (UNIX)
Getting File Status (UNIX) [message #97499] Fri, 28 June 2002 03:53 Go to next message
Sulaiman Gboyega N.
Messages: 17
Registered: April 2002
Junior Member
Hi All,

Please how can I get the status of a given file; that is whether it is being written to at the moment or not.

My scenario is that I have scheduled task that writes a file into a folder and another scheduled task that check this folder and pick the file when it is there.

The problem is that, I want the file to have been completely written before it is picked. So when the scheduled task to pick the file sees it, it must also know that it has been completely written before it picks it. The two tasks run from different servers so I couldn't make them into one single task.

I will appreciate any help please.


Re: Getting File Status (UNIX) [message #97501 is a reply to message #97499] Fri, 28 June 2002 07:11 Go to previous messageGo to next message
Messages: 578
Registered: January 2002
Senior Member
There are two tools that I know of fuser and lsof but they hack through the kernal data structures and by the time they do that the file may or may not be open. In other words it may be "open" when your program finishes so your program may still do the wrong action.

A better way would be to write a line at the end of your file from the writing process and grep for that or have some kind of notification from the writing process when it is complete.

I guess you could do two checks with the programs listed above with a wait time interval but seems like overkill to me.
Re: Thanks Everyone (Getting File Status) [message #97510 is a reply to message #97499] Tue, 02 July 2002 06:34 Go to previous message
Sulaiman Gboyega N.
Messages: 17
Registered: April 2002
Junior Member
Thanks everyone.

I eventually added all the ideas together and I was able to overcome this.

What I did this was, in addition to the file itself (say abc), I created another file called abc_ready, which contain just the cksum information for the file. This abc_ready will only be written once the process that writes the original file successfully complete. The process that picks the file will make sure the two files are ready and also make sure the cksum value in abc_ready is equivalent to its own cksum before attempting to read abc, and then delete abc_ready.

Thanks all once again.

Previous Topic: Re: 8.1.7 installation on Redhat 7.2
Next Topic: exp directly to tape
Goto Forum:

Current Time: Tue Sep 26 14:01:52 CDT 2023