快速查询日志命令

./tail.sh filename linenumber seratchText
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#字体颜色
blue_font="\E[34m\033[01m"
green_font="\033[1;32m"
yellow_font="\033[33m"
light_green_font_withbackcolor="\033[42;30m\033[01m"
light_green_font="\033[32m\033[01m"
red_font="\033[1;31m"

color_end="\033[0m"



#参数校验
if [ ! -n "$1" ] ;then
echo -e "${blue_font} 请指定日志文件目录 ! ${color_end}"
exit 1;
fi

line=$2

if [ ! -n "$2" ] ;then
line=20
fi

if [ ! -n "$3" ] ;then
echo -e "${yellow_font} 执行:tail -"$line"f $1 ${color_end}"
tail -"$line"f $1

else
echo -e "${yellow_font} 执行:tail -"$line"f $1 |grep "$3" ${color_end}"

tail -"$line"f $1 |grep "$3"
fi