Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a bash script that watches a folder, if something is added to the folder, the script will move all contents withing the monitored folder to the defined destination.

I have a few of these scripts that all have the same code, however, the monitored folder and destination folder are going to vary.

THE ISSUE: - The script fails to move the files in the monitored folder to the destination folder through FileZilla (FTP). Only one of the many scripts has this issue. The script does work if you move the file to the monitored folder manually through a shell prompt. FTP is the only format not working properly.

Any Ideas what the issue may be?

Here is the script:

inotifywait -m ~/Downloads/zzzfiles -e moved_to |
    while read path action file; do
        #echo "The file '$file' appeared in directory '$path' via '$action'"
        # do something with the file
    mv ~/Downloads/zzzfiles/* "/media/mynewdrive"
    done
share|improve this question

First, by having inotifywait -e moved_to only monitor for files moved to the target directory, you omit monitoring for files that were written or overwritten there, by, for example Filezilla. Add -e modify -e create to your command, or, unless you have a convincing reason to ignore some inotifywait events, discard all the -e whatever options.

Second, by not quoting the from files in your mv ~/Downloads/zzzfiles/* "/media/mynewdrive" command you run the risk of being caught by silly filenames, e.g. foo;rm -rf *. I would suggest

find ~/Downloads/zzzfiles/ -maxdepth 0 -type f -print0 | \
xargs -0 mv --target-directory=/media/newdrive --

which does the same thing, but more safely.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.