cron 命令不适用于共享主机中的 DirectAdmin

问题描述

我有以下 cron 命令,它与 CPanel 完美配合,但不能在 DirectAdmin 面板中工作。 此命令每分钟将一个以当前日期作为名称(例如 2021-03-09.zip)的 zip 文件从远程 URL 下载到本地目录。我附上了一封电子邮件以接收 cron 输出输出写在命令下面。我正在使用带有 apache 服务器和 PHP 的共享主机。

命令:

* * * * * /usr/bin/wget -U "anyuser" http://example.com/directory/`date +%Y-%m-%d`.zip -O /home/username/public_html/directory/`date +%Y-%m-%d`.zip

错误

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: Syntax error: unexpected end of file

解决方法

终于在尝试了很多事情之后我找到了有效的答案。 我只需要转义 % 符号,cron 就开始完美地工作了。使用反斜杠转义所有 % 符号,directadmin 控制面板开始识别它。谢谢。

* * * * * /usr/bin/wget -U "anyuser" http://example.com/directory/`date +\%Y-\%m-\%d`.zip -O /home/username/public_html/directory/`date +\%Y-\%m-\%d`.zip