diff --git a/grep_log.bat b/grep_log.bat new file mode 100644 index 0000000..0240b4f --- /dev/null +++ b/grep_log.bat @@ -0,0 +1,42 @@ +@echo off + +:: 1. 设置动态参数 +set REMOTE_IP=119.29.151.152 +set REMOTE_PORT=22101 +set REMOTE_USER=ubuntu +set SCRIPT_PATH=/home/ubuntu/grep_log.sh + +REM 检查是否提供了参数 +if "%~1"=="" ( + echo Usage: grep_log.bat [-A ] [-B ] [-C ] + exit /b 1 +) + +REM 设置变量 +set KEYWORD=%1 +shift + +REM 解析选项 +set OPTIONS= + +:parse_options +if "%~1"=="" goto done +if "%~1"=="-A" ( + set OPTIONS=-A %2 + shift +) +if "%~1"=="-B" ( + set OPTIONS=-B %2 + shift +) +if "%~1"=="-C" ( + set OPTIONS=-C %2 + shift +) +shift +goto parse_options + +:done + +REM 远程执行 Linux 脚本 +call ssh -p %REMOTE_PORT% %REMOTE_USER%@%REMOTE_IP% "bash %SCRIPT_PATH% %KEYWORD% %OPTIONS%" \ No newline at end of file diff --git a/shell/prod/advisor/deploy/grep_log.sh b/shell/prod/advisor/deploy/grep_log.sh new file mode 100644 index 0000000..3406086 --- /dev/null +++ b/shell/prod/advisor/deploy/grep_log.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +KEYWORD="3mc31t" + +# 目标服务器信息(格式:IP地址:端口) +SERVERS=( + "172.26.1.3:22" + "172.26.1.7:22" + "172.26.1.9:22" + "172.26.1.15:22" +) + +# 目标路径 +LOG_DIR="/data/logs/advisor" + +for SERVER in "${SERVERS[@]}"; do + # 获取 IP 和端口 + IP=$(echo $SERVER | cut -d ':' -f 1) + PORT=$(echo $SERVER | cut -d ':' -f 2) + + # 查询日期 + echo "log on $IP:" + ssh -p $PORT ubuntu@$IP "grep -n $KEYWORD $LOG_DIR/*.log" +done + +echo "All logs printed." \ No newline at end of file diff --git a/shell/prod/advisor/win/grep_log.bat b/shell/prod/advisor/win/grep_log.bat new file mode 100644 index 0000000..0240b4f --- /dev/null +++ b/shell/prod/advisor/win/grep_log.bat @@ -0,0 +1,42 @@ +@echo off + +:: 1. 设置动态参数 +set REMOTE_IP=119.29.151.152 +set REMOTE_PORT=22101 +set REMOTE_USER=ubuntu +set SCRIPT_PATH=/home/ubuntu/grep_log.sh + +REM 检查是否提供了参数 +if "%~1"=="" ( + echo Usage: grep_log.bat [-A ] [-B ] [-C ] + exit /b 1 +) + +REM 设置变量 +set KEYWORD=%1 +shift + +REM 解析选项 +set OPTIONS= + +:parse_options +if "%~1"=="" goto done +if "%~1"=="-A" ( + set OPTIONS=-A %2 + shift +) +if "%~1"=="-B" ( + set OPTIONS=-B %2 + shift +) +if "%~1"=="-C" ( + set OPTIONS=-C %2 + shift +) +shift +goto parse_options + +:done + +REM 远程执行 Linux 脚本 +call ssh -p %REMOTE_PORT% %REMOTE_USER%@%REMOTE_IP% "bash %SCRIPT_PATH% %KEYWORD% %OPTIONS%" \ No newline at end of file