crontab 使用日期时间命名重定向文件

使用月份命名

0 12 * * * sh /tmp/test.sh >> "/tmp/$(date +"\%Y-\%m").log"  2>&1

  

使用周命名

0 12 * * * sh /tmp/test.sh >> "/tmp/$(date +"\%Y-W\%W").log" 2>&1

  

使用小时命名

0 12 * * * sh /tmp/test.sh >> "/tmp/$(date +"\%Y-\%m-\%d_\%H").log" 2>&1

  

2>&1 表示把标准错误输出重定向到与标准输出一致

原文地址:https://www.cnblogs.com/abclife/p/11184714.html