小编d.r*_*.v.的帖子

如何使用 cron 添加时间戳来记录输出条目?

我正在尝试安排 htcacheclean 使用 cron 每半小时运行一次。服务本身运行良好,但我不知道如何获取时间戳以附加到日志条目本身(而不是 cron-log 文件名)。

我无法在任何地方找到关于如何将时间戳添加到日志条目本身的答案。我只不断看到有关如何将日期时间戳添加到 cron 日志文件名的问题和答案,这不是我想要做的。

crontab -e这就是我现在所拥有的:

0,30  *   *   *   *       /usr/sbin/htcacheclean -v -n -t -p/var/cache/apache/mod_disk_cache -l1M >> /path/to/cron-output.log 2>&1
Run Code Online (Sandbox Code Playgroud)

目前,这就是我的输出打印方式:

Statistics:
size limit 1.0M
total size was 167.4K, total size now 167.4K
total entries was 5, total entries now 5
Run Code Online (Sandbox Code Playgroud)

现在我只需要一个时间戳出现在“统计”之前的日志条目旁边。

编辑:

我正在尝试做的示例:

0000-00-00 00:00:00: Statistics:
size limit 1.0M
total size was 167.4K, total size now 167.4K
total entries was 5, total entries now 5
Run Code Online (Sandbox Code Playgroud)

我想添加年、月、日、时、分、秒。

提前致谢!

解决方案:

我想按照@glenn jackman 的建议在这里添加完整的解决方案。

0,30 …
Run Code Online (Sandbox Code Playgroud)

apache bash cron

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

apache ×1

bash ×1

cron ×1