歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

同時tail多個文件

普通的tail命令只能查看一個文件的輸出,保存如下內容為multail.sh  
#!/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 "$@"
do
        # show tails of each in background.
        tail -f $file &
done

# wait .. until CTRL+C
wait

 

使用方法:./multail.sh 文件1名 文件2名 ... 文件n名   結束方法: CTRL+C   http://www.thegeekstuff.com/2009/09/multitail-to-view-tail-f-output-of-multiple-log-files-in-one-terminal/
Copyright © Linux教程網 All Rights Reserved