0

I'm trying to write a simple cronjob that looks in a specific directory, performs a find command to determine if a file has been modified in the last two minutes, and if not, transfer that file to another directory.

I can find the files that need moving without any issues and rsync those files, but when I merge both commands, all files get moved even if they've been changed in the previous 2minutes.

So far, I've tried:

find /tmp/dir/* -cmin +2 | rsync -ogr --chown=user:group --remove-source-files --exclude=".*" /tmp/dir/* /tmp/dir2

As well as:

find /tmp/dir/* -cmin +2 -exec rsync -ogr --chown=user:group --remove-source-files --exclude=".*" {} /tmp/dir2 \;

I'm not sure what's going on, and why the find command which returns the proper files can't be piped or "exec-ed" properly into the rsync command.

Cheers in advance,

IknowImBad

1 Answers1

0

When you want to use a pipe, you have to tell rsync to read the source files from stdin: -include-from=-

I will be better to not use the asterisk character in find and rsync.

The *--exclude="." should not be needed.

find /tmp/dir/ -cmin +2 |
rsync -ogr --chown=user:group --remove-source-files --include-from=- /tmp/dir/ /tmp/dir2/
dinoex
  • 180