我想监视Linux中几个日志文件的变化。 基本上,我想看看哪个日志文件从一组20个文件中更新。 我已经检查了multitail工具,但是它的UI最多可以处理5个文件。
任何帮助表示赞赏。
对于你的build议,根据情况有很多方法可以做到这一点。
轻量级:看看inotify
更多fixtured(守护进程): fam (文件更改监视器)
或者,如果这不是一个普通的事情,你会做的:
或者closures一个:在您要观看的目录中watch -d -n 1 ls -t (仅在一个平面目录中,不能recursion,但可以修改它以便这样做),然后在结果上运行尾部。
如果您愿意从命令行执行此操作,则可以使用这样的脚本来执行此操作
# When this exits, exit all back ground process also. trap 'kill $(jobs -p)' EXIT # iterate through the each given file names, for file in "$@" do # show tails of each in background. tail -f $file & done # wait .. until CTRL+C wait
保存这个文件为multitail.sh或者你喜欢什么然后像这样执行
./multitail.sh file.txt file1.txt file2.txt file3.txt file4.txt file5.txt我只是跑这个,它成功地运行了6个文件,它的下面是只告诉你什么文字已经改变,而不是文件名的文本/日志文件。 我以前用过这个 欲了解更多信息,请看这里http://www.thegeekstuff.com/2009/09/multitail-to-view-tail-f-output-of-multiple-log-files-in-one-terminal/此人做了一个伟大的写作希望这有助于
有很多方法来剥皮这只猫…只是例如….
您可以使用logstash来聚合日志
如果他们都在同一个文件夹,你可以生成一个git仓库跟踪更改…
$ touch ~/test $ git init $ git add . $ echo "##this is a comment" >> ~/test $ git status | grep modified =># modified: test
你可以configuration监视文件的校验和,
check file /home/myhome/somefile.txt if changed checksum then alert check file /home/myhome/somefile2.txt if changed checksum then alert
也许这可能工作…
check directory /home/myhome/ if changed checksum then alert
或更轻的重量使用inotify工具来观察变化;
inotifywait -m -r --format '%f' -e modify -e move -e create -e delete ~/test | while read line do echo "hello $line" done
把事情简单化。 tail -f
例如:
tail -f file1 file2 file3 file4 file5
如果你真的只想看看哪个文件被改变了,只需用正确的sorting选项列出它们: ls -alt file1 file2 file3
这将在最上面显示最近更改的文件。
您甚至可以使用dynamic显示: watch -n 1 ls -alt file1 file2 file3