【发布时间】:2015-06-17 16:41:26
【问题描述】:
我需要一个 shell 脚本来轮换日志文件,同时它会不断更新。
#!/bin/bash
log-file=$1
if [ ! -f $log-file ]; then
echo "log file not found $log-file"
exit 1
fi
times-tamp=`date +%Y%m%d`
new-log-file=$log-file.$time-stamp
cp $log-file $new-log-file
cat /dev/null > $log-file
gzip -f -9 $new-log-file
我想知道在将消息从日志文件复制到新日志文件期间的飞行消息状态?
这些消息会丢失吗?如果我们丢失了飞行中的消息,那么我该如何轮换这些文件。
谁能帮我理解一下?
【问题讨论】:
-
不确定这是否是您需要的,但我的方法是创建每日文件并使用
find ./ -name log* -mtime +5 -delete删除 5 天前的文件