ubuntu -/bin/sh : -c: line 0: unexpected EOF while looking for matching `"'

标签 ubuntu cron sh

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/

相关文章:

linux - 从 bash 中的变量中提取子字符串

linux - 2g 在 sed 中无法跳过第一次出现的匹配项

macos - Samba 4.10 服务器配置 : using module "vfs_fruit" changes file creation mask for Mac clients,,我无法控制它

linux - Vim colorscheme 在启动时加载 - linux ubuntu gnome 终端

Python 脚本在 bash 中运行,但不在 cron 中运行?

bash - 使用 rvm 通过 cron 执行 rails runner 的 shell 脚本

函数 slqastrt、sqlacall、sqlastop 上的 Ubuntu DB2 gcc prep 错误

python - makecython++导致 fatal error : Python. h:尽管安装了python3-dev,但没有这样的文件或目录

node.js - 如果抓取数百万个 URL 并将数据更新到 mongodb,那么 cron 作业服务器是否密集?

linux - 如何在 Linux 中使用绝对路径创建链接?