Search code examples
bashamazon-web-servicesamazon-s3gnu-findutils

missing argument to -exec


I am having a problem with a bash command returning the following error:

/usr/bin/find: missing argument to `-exec'

The actual command I am running is:

/usr/bin/find /backup-directory/ -maxdepth 1 -type f -mtime +14 -printf "%f\n" -exec /usr/local/bin/aws s3 mv /backup-directory/{} s3://my-s3-bin/{}\;

The goal was to have this command called from the crontab nightly to search a directory and move any file older than 14 days to Amazon S3 using the aws cli.

The find command works correctly up until just before the -exec, with the following output:

/usr/bin/find /backup-directory/ -maxdepth 1 -type f -mtime +14 -printf "%f\n"
20161030002947.Pg
20161029002644.Pg
20161027002705.Pg
20161028002402.Pg
20161031002440.Pg

And just the aws cli move command with explicit file name to move works as intended: The following command will move 20161030002947.Pg for instance, from the local backup directory to the s3 bin.

/usr/local/bin/aws s3 mv /backup-directory/20161030002947.Pg s3://my-s3-bin/20161030002947.Pg

I don't know why it is breaking when I put them together with the -exec and {} parameters.

The reason everything is called from the full path is to make sure there are no unforeseen issues when the command is called from crontab, and the OS on this particular server is Debian 8.


Solution

  • I suggest to replace

    {}\; 
    

    by

    {} \;