Help with Shell Script automation

can someone look into this one please... I am struck at this point. I do not know what logic to be followed here. I can go ahead with my work only, if this step is done. Please Help.

I have a process X in a shell script. Once the process X is done, it generates a log file. Process X is basically a java application. We cannot assume how much time would be required for the process X to be completed once it is kicked off..

The shell script looks something like this:

date_current=`date +%m%d%y`

java -Xms512m -Xmx512m com.mainloader.databaseLoader S 12 F > file.log.$date1

I should write a shell script "Y" in such a manner, that my shell script "Y" should be able to

  1. check as and when the log file from the process X is created.
  2. once the log file is created, my script "Y" should be able to move the created log file to a different directory.

that is my script Y should automatically move the newly created log files to a different directory, immediately after the log file is created. I am not able to understand the logic here.

The safest thing to do is change process X, do not create a process Y.

date_current=`date +%m%d%y`
java -Xms512m -Xmx512m com.mainloader.databaseLoader S 12 F > file.log.$date1 fname="file.log.$date1"
mv $fname /path/to/new/${fname}

Otherwise you are stuck with a kludge-y kind of thing where you call lsof or fuser repeatedly until you see that the logfile is no long open. See the man page on your system

example:

lsof /path/to/file.log.$date1
while [[ $? -ne 0 ]]
do
       sleep 10
       lsof /path/to/file.log.$date1
done

This does a lot of pointless polling. If your system has inotify (Linux/GNU derivative) you can call inotify to see when a file is closed. Same polling problem though.