Quote:
I always get the mv error, however if I change the script to do the rename a different way it will work when I test it with cron! However sure enough it will fail when a new file comes in the next day!
Because when you test, the sftp is completed and nothing is locking the file letting you rename/move with no problems.
You probably need to change the way the sftp works - meaning, send a second file (either a 0 byte file or one with the checksum of the first file in it), check that the second file is there (due to it's small size, you can sleep 2 seconds and have no issue opening it to grab the checksum info).
Steps:
1. sftp sending original file
2. Your cron job kicks off - sftp may still be sending file
3. Cron job waits for 2nd file.
4. sftp finishes sending first file.
5. sftp sends second file.
6. cron job finds second file - 'knows' it's safe to manipulate first file
7. If you decide to send checksum info - check info sent versus what your system shows as checksum - should be the same.
If that can't be done (you don't control what sftp is sending), then you can list the original file - wait until it stops getting bigger. Or, look for the sftp process, wait until it is gone. But the checksum is a great way of insuring your file is the same as original.