参考的链接: http://www.2cto.com/os/201311/259532.html
不过上面的这个链接也是转载的,参考的链接为:
有时候单个应用在多个文件里输出日志,需要同时动态查看多个日志文件
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文件中,如
multi-tail.sh
即可.
如果想硬编码入参值,比如说入参是1 2 3,可以将脚本里的files=$@替换成files=(1 2 3)
转载于:https://blog.51cto.com/tenfee/1925739