File locking (Unix/Linux) & sftp

Hi all,

Can anyone help ...on how to ensure that a file is locked .

thanks & regards,
Soodoo
----------------------------------------

Problem description: -

We usually use the mv command in scripts to make sure that a file is complete and not being written to by another process.

If the mv is successful, we are confident that we can copy/ftp/process the file in confidence.

Based on tests conducted, we found that a mv on AIX will be successful even if a sftp of the file is under way.

Kindly note that we made sure that both source and destination directories were on the same file system (so that the mv would be a move and not a copy operation).

To make matters worse, a rm of a file that is being sftp'ed also worked. That is the rm command completed successfully, even before the sftp had completed, and at the end of the sftp, the file was just not there anymore!

NB: AIX version 6.1
sfp (Bitwise) 4.23

You can do something like below, where the second command (sftp)will execute only if the first command (mv) is successful

mv source dest && sftp ...