Wait until the zip is completely written, continue, Bash Script

I'm trying to zip a file and then FTP upload using a bash script, but it downloads a corrupted zip file. I have looked around and I am trying to use lsof | grep to confirm the file is complete, but I'm not really sure what I'm doing.

So, I have a

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 <<EOF
open myserver
user user pass
put test.zip
EOF
done

      

and test.zip is corrupted during its download, so it is not readable on another server, but on the server it zipped everything good on it by the time it was checked.

Some advice would be appreciated, I'm fairly new to this and try to search around the heap to find a solution, not too sure if I'm going in the right direction. Thanks in advance.

+3


source to share


2 answers


From the man page:

put local file [remote-file]                  Save the local file on the remote computer. If no remote file is specified, the local file name is used after processing according to any ntrans or nmap setting when naming the remote file. File transfer uses the current settings for type, format, mode, and structure.

I guess the problem is that you are not transferring files in BINARY mode.



Try the following:

ftp -n <<EOF
open myserver
user user pass
binary
put test.zip
EOF

      

+4


source


Try it.



PID=$(pgrep zip)
while [[ ( -d /proc/$PID) ) && ( -z `grep zombie /proc/$PID/status` ) ]]; do
    sleep 1
done

      

0


source







All Articles