#!/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/