title: Wait until zip fully written then continue, Bash Script
body: <p>I've been trying to zip a file and then upload it by FTP using a bash script, but it's uploading a corrupt zip file. I've had a look around and I'm trying to use lsof | grep to confirm the file is complete but I'm not really sure what I'm doing.</p>
  
  <p>So I've got</p>
  
  <pre><code>cd /var/test/tobezipped
  zip -r test.zip *
  FOLDER="/var/test/tobezipped"
  ZIPS=$(ls $FOLDER)
  for F in $zips ; do
    while [ -n "$(lsof | grep $F" ] ; do
    sleep 1
  done
  ftp -n &lt;&lt;EOF
  open myserver
  user user pass
  put test.zip
  EOF
  done
  </code></pre>
  
  <p>and test.zip is corrupt at the time it's being uploaded, so on the other server it's not readable but on the server it's zipped on it's all good by the time I check it.</p>
  
  <p>Any kind of advice is appreciated, I'm pretty new to this sort of thing and tried to search around heaps to find a solution, not too sure I'm going in the right direction. Thanks in advance.</p>