我想保存我的 crontab 输出:
15 * * * * myscript.sh > ~/logs/log1.txt
如何让 crontab 每次都保存到新文件(即 log2.txt、log3.txt 等),而不是更新或覆盖旧文件?
也许我可以使用某种实用程序来做到这一点?
我正在使用 CENT OS 5。
谢谢 ;)
答案1
您可以使用日期并花时间创建一个唯一的文件名
15 * * * * myscript.sh > ~/logs/log.$(/bin/date +\%Y\%m\%d\%H\%M\%S).txt
这将创建名为 ~/logs/log.20110426121501.txt
答案2
if you can't use the date as answered by Iain
from your script output a watermark like ###
this is what I have into test.txt
###
test
###
test1
then to process it
shell$ awk -F "###" {'print $1'} test.txt
test
test1
i have the delimiter changed from ' ' into awk to '###' and then just print the lines