UNIX -Tracking File I/O

Hi Team,

I have a requirement. We are processing 100s of thousands of files and had to tar 10K files each

The problem I face is, I would need to add the file into tar only when the write operation in the file is complete. How would I achieve this.

OS : Sun Solaris 5.8
Shell : KSH

---------- Post updated at 03:21 PM ---------- Previous update was at 03:20 PM ----------

No code fragments or data samples in this post

Are these files created/written for a set time? For example, 5 minute logs? If so, you could select only files which are greater than 5 minutes old.

Please elaborate on the scenario with regards to these files time frames.

The file is not getting generated on a fixed time unfortunately

Okay, so how are they being created???

Are files created, written to, and then permanently closed? Or could they be reopened?

Hi,

The files are created by another process. The file write once complete, it will not be re-opened again.

The fuser command lists the opening processes. If nothing is listed then the file is not opened.
Example shell script:

pids=`fuser filename 2>/dev/null`
if [ -z "$pids" ]
then
  echo "not opened"
fi

The fuser command requires the sys_mount privilege. So while using fuser is a great, answer you need advanced privilege for the process running it.