相关疑难解决方法(0)

如何在 cron 选项卡作业中执行`date`?

我想为日志文件名中包含当前小时的 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 脚本来执行此操作?

cron quoting command-substitution

165
推荐指数
4
解决办法
15万
查看次数

运行存储在 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 也能很好地打开。

为什么?

shell zsh quoting variable

7
推荐指数
2
解决办法
2969
查看次数

标签 统计

quoting ×2

command-substitution ×1

cron ×1

shell ×1

variable ×1

zsh ×1