如何验证文件更新是否不超过 55 分钟?
例如,文件IOstatDisk2.log自 18:00 起未更新,当前时间是 19: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 - file isnt update more 55 min” >> IOstatDisk2.log
但如果最后一个时间戳少于 55 分钟,那么我不会添加该行
echo “new cycle - file isnt update more 55 min” >> IOstatDisk2.log
- 我使用 solaris 8/9/10
答案1
您可以使用inotify 工具。Inotifywatch 可以观察文件,并在对这些文件执行某些操作(例如创建、删除等)时向您发送消息。因此,每个小时您都可以设置一个标志,然后使用 inotify 的调用将其重置。以下是示例man inotifywatch
:
观察 `~/.beagle' 目录 60 秒:
% inotifywatch -v -e access -e modify -t 60 -r ~/.beagle
Establishing watches...
Setting up watch(es) on /home/rohan/.beagle
OK, /home/rohan/.beagle is now being watched.
Total of 302 watches.
Finished establishing watches, now collecting statistics.
Will listen for events for 60 seconds.
total access modify filename
1436 1074 362 /home/rohan/.beagle/Indexes/FileSystemIndex/PrimaryIndex/
1323 1053 270 /home/rohan/.beagle/Indexes/FileSystemIndex/SecondaryIndex/
303 116 187 /home/rohan/.beagle/Indexes/KMailIndex/PrimaryIndex/
261 74 187 /home/rohan/.beagle/TextCache/
206 0 206 /home/rohan/.beagle/Log/
42 0 42 /home/rohan/.beagle/Indexes/FileSystemIndex/Locks/
18 6 12 /home/rohan/.beagle/Indexes/FileSystemIndex/
12 0 12 /home/rohan/.beagle/Indexes/KMailIndex/Locks/
3 0 3 /home/rohan/.beagle/TextCache/54/
3 0 3 /home/rohan/.beagle/TextCache/bc/
3 0 3 /home/rohan/.beagle/TextCache/20/
3 0 3 /home/rohan/.beagle/TextCache/62/
我相信 inotify 本身可能不适用于 Solaris,但这里有一个一篇关于等效的文章(?)