手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2017年08月31日的文章

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

 如题,直接上代码(COPY来的)

http://tenfee.blog.51cto.com/6353835/1925739
  1. #!/bin/sh  
  2. function clean()  
  3. {  
  4.   #echo $@;  
  5.   #for file in "$@"; do ps -ef|grep $file|grep -v grep|awk '{print $2}'|xargs kill -9; done  
  6.   jobs -p|xargs kill -9  
  7. }  
  8. files=$@  
  9.   
  10. # When this exits, exit all back ground process also.  
  11. #trap "ps -ef|grep tail|grep -v grep|awk '{print "'$2'"}'|xargs kill -9" EXIT  
  12. trap "clean $files " EXIT  
  13.   
  14. # iterate through the each given file names,  
  15. for file in "${files[@]}"  
  16. do  
  17.     # show tails of each in background.  
  18.     tail -f $file &  
  19. done  
  20.   
  21. # wait .. until CTRL+C  
  22. wait