我有一个crontab
条目:
00 10 * * * test.sh>>output_log 2>>error_log
但我想也包括日期为output_log
和error_log
在每一天的开始行。
我怎样才能做到这一点?
我试过了:
{ echo `date` && . test.sh; }>>output_log 2>>error_log
但它仅在 output_log 中包含日期,因为echo date
不被视为stderr
因此不包含在2
.
我想要这样的伪代码:
{ echo `date` && . test.sh }>>output_log { echo `date` plus 2's content } >>error_log
最简单的:
0 10 * * * { date; date >&2; test.sh; } >> output_log 2>> error_log
使用ts
Moreutils的实用程序也可能很有趣,它会在每一行前面加上时间戳:
SHELL=/bin/bash
0 10 * * * test.sh > >(ts >> output_log) 2> >(ts >> error_log)
(注意使用/bin/bash
,因为最基本的 POSIX/bin/sh
不支持>()
重定向构造。)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句