腳本名: 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