How to detect files transmission at UNIX server ?

Dear Expert Users,

I know that Unix utility ( fuser ) is used to detect "transmission" of files from Source system to "current Linux Server".

I have scheduled this Unix script to work every 30th minutes of the hour and whenever files transmission starts at that very moment.
And, the file is picked up for transmission even though the file has not fully arrived at the "current Linux server".

This is the problem .. Kindly help ??

 # Check if the file is still being written at the Server
/bin/fuser -u ${FILE} > ${LOCAL_PATH}/process_file 2>/dev/null
PROCESS_ID=`cat ${LOCAL_PATH}/process_file`
if [ ${PROCESS_ID} ] ; then
echo "${FILE} file is still being written. Will attempt to sFTP at next iteration" >> ${LOGFILE}
echo "${FILE} file is still being written. Will attempt to sFTP at next iteration"
echo
echo "------------------------" >> ${LOGFILE}
echo
else
echo "Create batchfile for the file, ${FILE}" >> ${LOGFILE}
echo "Create batchfile for the file, ${FILE}"
. ${SCRIPT_PATH}/Create_batchfile.sh
echo 
 

How about the sending side to put .TMP (or similar temporary extension), and when copy is over use mv command.

This would be an atomic operation on same filesystem, and your script would not need fuser at all.

What is the way 'transmission' is happening (ftp,scp or ) ?

Hope that helps
Regards
Peasant.

Dear Peasant and Unix Experts,

Thank you for your message !!

Source system is a Mainframe Server and it sends files to "current Linux server". Unfortunately, we will not be able to use your suggestions here. They use CDGW software to transmit files to "current server".

And, I am using SFTP utility to further pick up the files from "current server" and send it again to "destination Linux Server". Kindly suggest any work-around or better logic in using "fuser" utility ??

Thank you.

Connect direct software has built in functionality to prevent just the problem you are having.
Just modify the rule to make a mv to original name after a successful transfer, don't reinvent the wheel.

If you really want to, search the forums for fuser,lsof and pfiles examples who to find out if file is being used.

Hope that helps
Regards

Dear Peasant and Unix Experts,

As I mentioned before, CD software is used to transmit files from "Source Server" to "current server". We don't have CDGW software on the "current server" where I am running this SFTP script to detect complete arrival of files using "fuser" utility.

Here is the file transmission path:

"Source Sever" ---CDGW----> "Current Server" ( I used SFTP shell script ) ------> "Destination Server"

Kindly suggest any better ways to use this "fuser" utility ?

Thank you.