Cron 无法运行作业并向我发送此电子邮件:
标题:
cd /var/www/www-root/data/www/mysite.com/laravel/ && find ./ -mtime -1 -type f -printf "
body :
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
我正在使用 ISPmanager,这是 cron 工作:
cd /var/www/www-root/data/www/mysite.com/nuxt/ && find ./ -mtime -1 -type f -printf "%p\n" | while read name ; do zip /var/www/www-root/data/www/mysite.com/laravel/storage/app/backup/nuxt_files.zip $name; done
该代码在 ssh bash 中完美运行,即使我通过按 ISPmanager 中的“运行”按钮运行该 cron 作业。我不知道cron有什么问题。
最佳答案
cron
替换 %
在将命令发送到 shell 之前使用换行符。包含文字 %
,你需要逃避它:
cd /var/www/www-root/data/www/mysite.com/nuxt/ &&
find ./ -mtime -1 -type f -printf "\%p\n" |
while read name ; do
zip /var/www/www-root/data/www/mysite.com/laravel/storage/app/backup/nuxt_files.zip $name; done
来自
man 5 crontab
:Percent-signs (%) in the command, unless escaped with backslash (), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.
因此,您正在尝试使用
"
运行第一个命令(带有不匹配的 p\n" ...
)作为其输入。
关于ubuntu -/bin/sh : -c: line 0: unexpected EOF while looking for matching `"',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60476937/