如果在55分钟内未更改任何日志文件,则需要对其进行更新。例如,假设现在是19:00,IOstatDisk2.log
自18:00以来没有更改过:
solaris1a:/var/tmp ROOT # ls -ltr IOstatDisk2.log
-rw-r--r-- 1 root other 6 Aug 2 18:00 IOstatDisk2.log
因此,在这种情况下,我将添加该行
echo “new cycle - forced update after 55 min.” >> IOstatDisk2.log
但是,如果最后一个时间戳记少于55分钟之前,那么我将不添加该行。
您可以通过以下方式对其进行测试(如果测试成立,则可以在文件上进行操作):
if [ $(((`date +%s` - `stat -c %Y IOstatDisk2.log`) / 60)) -ge 55 ]
then
echo "File was modified more than 55 minutes ago"
# do something with the file...
fi
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句