|
@@ -0,0 +1,17 @@
|
|
|
+#!/bin/bash
|
|
|
+
|
|
|
+# 进入指定目录
|
|
|
+cd "/logs/$1"
|
|
|
+
|
|
|
+# 获取最新修改的文件
|
|
|
+latest_file=$(ls -t | head -n1)
|
|
|
+
|
|
|
+# 查找入参2所在行
|
|
|
+matching_line=$(grep -n "$2" "$latest_file" | head -n1)
|
|
|
+
|
|
|
+# 获取匹配行号和文件名
|
|
|
+line_number=$(echo "$matching_line" | cut -d ":" -f 1)
|
|
|
+# file_name=$(echo "$matching_line" | cut -d ":" -f 2)
|
|
|
+
|
|
|
+# 查找前30行和后200行数据
|
|
|
+awk -v start=$((line_number-30)) -v end=$((line_number+200)) 'NR>=start && NR<=end' "$latest_file"
|