grep拉取日志,指定獲取最近N條記錄


腳本名: mgrep

#!/bin/bash
source=/opt/dwebvideo_tomcat/logs/catalina.out
a=10
# 讀取輸入
if [ -n "$2" ]; then
	a=$2
fi
echo -e "\e[31m >>>--結果:---------> \e[0m"
grep -E "$1" $source --color=auto -n | tail -n $a | grep -E "$1" --color=auto

使用示例:

  • 獲取最近10條
    ./mgrep 關鍵字 默認就是10條

  • 獲取最近5條
    ./mgrep 關鍵字 5


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM