【问题标题】:/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'/bin/sh: -c: line 0: 在寻找匹配的 `"' 时出现意外的 EOF
【发布时间】:2020-06-14 01:06:27
【问题描述】:

Cron 无法运行作业并向我发送此电子邮件:

标题:

cd /var/www/www-root/data/www/mysite.com/laravel/ && find ./ -mtime -1 -type f -printf "

正文:

/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 出了什么问题。

【问题讨论】:

    标签: ubuntu cron sh


    【解决方案1】:

    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

    命令中的百分号 (%),除非 用反斜杠 () 转义,将变为换行符,并且 第一个 % 之后的所有数据都将作为标准输入发送到命令。

    因此,您尝试使用p\n" ... 作为输入来运行第一个命令(带有不匹配的")。

    【讨论】:

      猜你喜欢
      • 2018-10-19
      • 1970-01-01
      • 2020-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多