I need to deploy an automated process (via 1 min cron script) that looks for tar files in a specific directory. If a tar file is found, it is untarred to the appropriate location and then the tar file is deleted.
The tar files are automatically copied to this server over SSH from another server. In some cases, the tar files are extremely large, with lots of files.
The problem that I am expecting to run into: If it takes > 1 minute for the tar file to be copied to the server, and the cron script runs once every minute, it's going to see the .tar.gz file and try to do untar it, even though the tar file is still in the process of being written to.
Is there any way (via bash commands) to test if a file is currently being written to, or if it's only a partial file, etc?
One alternative I was thinking of was to have the file be copied as a different file extension (like
.tar.gz.part) and then renamed to
.tar.gz after the transfer is complete. But I figured I'd try to figure out if there is simply a way to determine if the file is whole at the command line first... Any clues?