日志脚本
This commit is contained in:
parent
47167a7489
commit
90ef2ed34f
42
grep_log.bat
Normal file
42
grep_log.bat
Normal file
@ -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 <KEYWORD> [-A <n>] [-B <n>] [-C <n>]
|
||||
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%"
|
||||
26
shell/prod/advisor/deploy/grep_log.sh
Normal file
26
shell/prod/advisor/deploy/grep_log.sh
Normal file
@ -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."
|
||||
42
shell/prod/advisor/win/grep_log.bat
Normal file
42
shell/prod/advisor/win/grep_log.bat
Normal file
@ -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 <KEYWORD> [-A <n>] [-B <n>] [-C <n>]
|
||||
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%"
|
||||
Loading…
x
Reference in New Issue
Block a user