Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 缺少-exec的参数_Bash_Amazon Web Services_Amazon S3_Gnu Findutils - Fatal编程技术网

Bash 缺少-exec的参数

Bash 缺少-exec的参数,bash,amazon-web-services,amazon-s3,gnu-findutils,Bash,Amazon Web Services,Amazon S3,Gnu Findutils,bash命令返回以下错误时出现问题: /usr/bin/find: missing argument to `-exec' 我正在运行的实际命令是: /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/{}\; 其目标是每晚从crontab调用此命令,以搜

bash命令返回以下错误时出现问题:

/usr/bin/find: missing argument to `-exec'
我正在运行的实际命令是:

/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/{}\;
其目标是每晚从crontab调用此命令,以搜索目录,并使用aws cli将任何超过14天的文件移动到Amazon S3

find命令在-exec之前一直正常工作,输出如下:

/usr/bin/find /backup-directory/ -maxdepth 1 -type f -mtime +14 -printf "%f\n"
20161030002947.Pg
20161029002644.Pg
20161027002705.Pg
20161028002402.Pg
20161031002440.Pg
只有带有显式文件名的aws cli move命令才能按预期工作:例如,以下命令将2016103002947.Pg从本地备份目录移动到s3 bin

/usr/local/bin/aws s3 mv /backup-directory/20161030002947.Pg s3://my-s3-bin/20161030002947.Pg
当我将它们与-exec和{}参数组合在一起时,我不知道为什么会出现问题

从完整路径调用所有内容的原因是,当从crontab调用命令时,确保没有不可预见的问题,并且此特定服务器上的操作系统是Debian 8。

我建议替换它

{}\; 

我建议更换

{}\; 


那至少让它执行吧,谢谢你。但现在我得到了意想不到的结果。看起来它可能不遵守-printf“%f\n”。20161030002947.Pg用户提供的路径/备份目录//备份目录/20161030002947.Pg不存在。20161029002644.Pg用户提供的路径/backup directory//backup directory/201610229002644.Pg不存在。我只是通过用echo替换aws命令来测试这一点,我肯定对
-printf“%f\n”
的功能有误解,因为完整路径仍在
{}
…这是echo的输出:
find/backup directory/-maxdepth 1-type f-mtime+14-printf“%f\n”-exec echo/backup directory/{}s3:/my-s3-bin/{};20161030002947.Pg/backup directory//backup directory/20161030002947.Pg s3://my-s3-bin//backup directory/20161030002947.Pg
Printf写入标准输出。它不影响-exec.Cron对
%
有一些不可思议的荒谬处理。最简单的解决方法是将命令放在bash脚本中,并使用cron启动脚本。我能够通过使用
sh-c
basename
以及上面的建议使其工作。因此,使用aws cli将满足查找条件的所有
filename
sourcedir
移动到
destinationbin
的简化示例版本是:
find/sourcedir/-maxdepth 1-type f-mtime+14-exec sh-c'aws s3 mv/sourcedir/$(basename$1)s3://destinationbin/$(basename$1)'find sh{}
…这完全消除了对
%
的需求,因为
-printf
只有在管道中才能工作。我使用了来自的信息来提供帮助。这至少让它得以执行,所以谢谢你。但现在我得到了意想不到的结果。看起来它可能不遵守-printf“%f\n”。20161030002947.Pg用户提供的路径/备份目录//备份目录/20161030002947.Pg不存在。20161029002644.Pg用户提供的路径/backup directory//backup directory/201610229002644.Pg不存在。我只是通过用echo替换aws命令来测试这一点,我肯定对
-printf“%f\n”
的功能有误解,因为完整路径仍在
{}
…这是echo的输出:
find/backup directory/-maxdepth 1-type f-mtime+14-printf“%f\n”-exec echo/backup directory/{}s3:/my-s3-bin/{};20161030002947.Pg/backup directory//backup directory/20161030002947.Pg s3://my-s3-bin//backup directory/20161030002947.Pg
Printf写入标准输出。它不影响-exec.Cron对
%
有一些不可思议的荒谬处理。最简单的解决方法是将命令放在bash脚本中,并使用cron启动脚本。我能够通过使用
sh-c
basename
以及上面的建议使其工作。因此,使用aws cli将满足查找条件的所有
filename
sourcedir
移动到
destinationbin
的简化示例版本是:
find/sourcedir/-maxdepth 1-type f-mtime+14-exec sh-c'aws s3 mv/sourcedir/$(basename$1)s3://destinationbin/$(basename$1)'find sh{}
…这完全消除了对
%
的需求,因为
-printf
只有在管道中才能工作。我使用了来自的信息来提供帮助。