參考的連接: http://www.2cto.com/os/201311/259532.html html
不過上面的這個連接也是轉載的,參考的連接爲:java
有時候單個應用在多個文件裏輸出日誌,須要同時動態查看多個日誌文件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