views:

30

answers:

1

I've got:

$ rsync -azv zope@myserver:/smb/Data/*/*/* ~/rsynced_samples/

And I want it to run forever, syncing any new file as soon as it appears on myserver:

(specifying a poll interval, such as 4 seconds would be an ok comprise)

A: 

Instead of rsync you can use inotifywait which use kernel specific file changes triggers.

This script (inotify.sh) can you give an idea:

#!/bin/bash

directory=$1

inotifywait -q -m --format '%f' -e modify -e move -e create -e delete ${directory} | while read line

do
    echo "doing something with: $line";

    # for example:
    # cp $line to <somewhere>

You can invoke this script specifying the "monitor" directory, in this way

./inotify.sh ~/Desktop/

The $line variable contains the full file path.

If you want to limit to only newly created files you can use on the flag "-e create"

Impiastro