我正在尝试使用 cron 每分钟将当前日期和时间附加到日志文件中。我希望以特定方式设置日期和时间的格式。
这个有效:
* * * * * date >> /home/user/time1.txt
这不是:
* * * * * date +%Y%m%d%H%M%S >> /home/user/time2.txt
非常感谢任何见解!
最佳答案
问题是 cron
将 %
视为换行符。你需要逃避他们
来自 crontab POSIX man
页面:
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.
* * * * * date +\%Y\%m\%d\%H\%M\%S >> /home/user/time2.txt
关于linux - cron 任务不写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47975137/