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 network share on my system to which our plotter scanner sends its scanned files. How can I write a script to automatically copy newly added files to another folder?

share|improve this question

cron and rsync would be my tools of choice. I'm going to assume you've mounted this network share through naultilus or another method. There are other, better ways to mount things than through Naultilus (especially for scripting purposes) but I'll leave that up to you:

Open a terminal and run crontab -e. You might be asked to select an editor (nano is easiest). In there you want to add a new line that looks something like this:

*/5 * * * * rsync -avz ~/.gvfs/remote/path/ ~/scans/

Control-x, then y to save.

That will sync everything down from ~/.gvfs/remote/path/ to ~/scans/ every five minutes. It won't re-download things that haven't changed. Of course you'll want to edit the paths and you might want to change the timing for the cron statement. You might want to limit it to in-hours, or run it more often.

share|improve this answer
  • Let $share contain the path to your "share (...)to which our plotter scanner sends its scanned files"
  • Let $afolder contain the path to your "another folder"

My simplisctic approach would be to keep a list of files in $share. Write a script that checks if the files currently in $share are in this list. It not, they must be new and should be moved. Then add this script to cron thus running it regularly.

Let $filelist contain the path to said filelist.

Script (not tested - just a template):


...variables as discussed....

find "$share" -type f >> /tmp/foundfiles
while read fnd; do  #walk files in folder
    while read listitem; do  #walk listitems
        if [ "$fnd" -ef "$listitem" ]; then
            echo "$fnd Allready in list."
    done < "$filelist"
    if [ ! -n "$isinlist ]; then
        echo "$fnd" >> "$filelist"
        cp "$fnd" to "$afolder"
done < /tmp/foundfiles
rm /tmp/foundfiles
exit 0

There are tools that do that for you, like rsync. But maybe you want to add some custom-funtionality.

share|improve this answer

Your Answer


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.