在crontab中,你可以这样做吗?
* * * * * echo $( date +%F) >> /path/date.txt
Run Code Online (Sandbox Code Playgroud)
bmk*_*bmk 32
你的crontab行的实际问题不是$()或反引号.问题是百分号%.它在crontabs中具有特殊含义.
从联机帮助页:
...
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.
...
Run Code Online (Sandbox Code Playgroud)
如果你使用\它来转义百分号,它应该按预期工作:
* * * * * echo $(date +\%F) >> /tmp/date.txt
Run Code Online (Sandbox Code Playgroud)
要么
* * * * * echo `date +\%F` >> /tmp/date2.txt
Run Code Online (Sandbox Code Playgroud)
都在我的网站上工作.
| 归档时间: |
|
| 查看次数: |
2223 次 |
| 最近记录: |