我想为日志文件名中包含当前小时的 cron 脚本创建一个日志文件。这是我尝试使用的命令:
0 * * * * echo hello >> ~/cron-logs/hourly/test`date "+%d"`.log
Run Code Online (Sandbox Code Playgroud)
不幸的是,我在运行时收到此消息:
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
Run Code Online (Sandbox Code Playgroud)
我曾尝试date
以各种方式逃避该部分,但运气不佳。是否可以在 crontab 文件中内嵌进行此操作,或者我是否需要创建一个 shell 脚本来执行此操作?
以下在我的 shell (zsh) 中有效:
> FOO='ls'
> $FOO
file1 file2
Run Code Online (Sandbox Code Playgroud)
但以下没有:
> FOO='emacs -nw'
> $FOO
zsh: command not found: emacs -nw
Run Code Online (Sandbox Code Playgroud)
即使emacs -nw
直接调用Emacs 也能很好地打开。
为什么?