用tail同时查看多个文件的日志输出

参考的连接: http://www.2cto.com/os/201311/259532.html html

不过上面的这个连接也是转载的,参考的连接为:java

http://www.thegeekstuff.com/2009/09/multitail-to-view-tail-f-output-of-multiple-log-files-in-one-terminal/ ide

有时候单个应用在多个文件里输出日志,须要同时动态查看多个日志文件this

tail 不支持同时动态输出多个文件的日志.
编码

#!/bin/sh
function clean()
{
  #echo $@;
  #for file in "$@"; do ps -ef|grep $file|grep -v grep|awk '{print $2}'|xargs kill -9; done
  jobs -p|xargs kill -9  
}
files=$@
 
# When this exits, exit all back ground process also.
#trap "ps -ef|grep tail|grep -v grep|awk '{print "'$2'"}'|xargs kill -9" EXIT
 
trap "clean $files " EXIT
 
# iterate through the each given file names,
for file in "${files[@]}"
do
        # show tails of each in background.
        tail -f $file &
done
 
# wait .. until CTRL+C
wait

将上述脚本复制到某个sh文件中,如spa

multi-tail.sh

便可.日志

若是想硬编码入参值,好比说入参是1 2 3,能够将脚本里的files=$@替换成files=(1 2 3)htm

相关文章
相关标签/搜索