From 4d90bba99df9dfcf513ab036caba25b3fe34841f Mon Sep 17 00:00:00 2001 From: linmianxun <634841751@qq.com> Date: Sun, 13 Sep 2026 21:19:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E7=B4=A7=E6=B5=8B=E6=9C=8D=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=9B=91=E8=A7=86=E8=84=9A=E6=9C=AC=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=EF=BC=8C=E5=87=8F=E5=B0=91=20health=20=E6=8E=A2=E6=B4=BB?= =?UTF-8?q?=E5=88=B7=E5=B1=8F=EF=BC=8C=E4=BE=BF=E4=BA=8E=E6=8E=92=E6=9F=A5?= =?UTF-8?q?=E4=BC=81=E5=BE=AE=E5=9B=9E=E8=B0=83=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- deploy/Watch-Agent8910.ps1 | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/deploy/Watch-Agent8910.ps1 b/deploy/Watch-Agent8910.ps1 index 45a9896..a57fe4c 100644 --- a/deploy/Watch-Agent8910.ps1 +++ b/deploy/Watch-Agent8910.ps1 @@ -17,19 +17,21 @@ param( ) $ErrorActionPreference = 'Stop' -$Key = Join-Path $env:USERPROFILE '.ssh\id_ed25519_ytd' -$Remote = 'ytd_extdev_0903@129.211.181.80' +$SshKey = Join-Path $env:USERPROFILE '.ssh\id_ed25519_ytd' +$SshHost = 'ytd_extdev_0903@129.211.181.80' $LogOut = 'E:\wwwroot\logs\agent-http.out.log' $LogErr = 'E:\wwwroot\logs\agent-http.err.log' +$IncomingRemotePath = 'C:/Users/ytd_extdev_0903/incoming/_watch_agent8910.ps1' +$IncomingLocalRun = 'C:\Users\ytd_extdev_0903\incoming\_watch_agent8910.ps1' -# 企微回调 / 出站 / 注入 / 常见失败码;-All 时不使用 -$Pattern = 'wecom|callback|inject|outbox|inbox|errcode|errmsg|60020|ERROR|WARNING|Traceback|Exception|health|sender|touser|crypto' +# 企微回调 / 出站 / 注入 / 失败;故意不含纯 /health 探活行,避免刷屏 +$Pattern = '/wecom/callback|inject-text|inject:|outbox|inbox|errcode|errmsg|60020|ERROR|WARNING|Traceback|Exception|ModuleNotFoundError|sender=|touser=|crypto|ChannelRuntime|dispatch intent' -if (-not (Test-Path $Key)) { - throw "缺少 SSH 密钥: $Key" +if (-not (Test-Path $SshKey)) { + throw "缺少 SSH 密钥: $SshKey" } -Write-Host "目标: ${Remote}" +Write-Host "目标: $SshHost" Write-Host "日志: $LogOut" Write-Host " $LogErr" if ($All) { @@ -39,11 +41,11 @@ if ($All) { } Write-Host '---' -# 远程脚本:先打 health,再 Tail;-Wait 仅在非 Once 时启用 $waitLiteral = if ($Once) { '$false' } else { '$true' } $allLiteral = if ($All) { '$true' } else { '$false' } -$remote = @" +# 远程执行体:先 health,再 Tail;持续模式用 -Wait +$remoteScript = @" `$ErrorActionPreference = 'Continue' `$out = '$LogOut' `$err = '$LogErr' @@ -88,16 +90,12 @@ Write-Output 'following... (Ctrl+C to stop)' Get-Content -Path `$files -Tail `$tail -Wait -ErrorAction SilentlyContinue | ForEach-Object { Show-Line `$_ } "@ -$remoteFile = Join-Path $env:TEMP 'ytd-watch-agent8910-remote.ps1' -Set-Content -Path $remoteFile -Value $remote -Encoding UTF8 +$localTemp = Join-Path $env:TEMP 'ytd-watch-agent8910-remote.ps1' +Set-Content -Path $localTemp -Value $remoteScript -Encoding UTF8 -$incoming = 'C:/Users/ytd_extdev_0903/incoming/_watch_agent8910.ps1' -& scp -o BatchMode=yes -o ConnectTimeout=12 -i $Key $remoteFile "${Remote}:${incoming}" +& scp.exe -o BatchMode=yes -o ConnectTimeout=12 -i $SshKey $localTemp "${SshHost}:${IncomingRemotePath}" if ($LASTEXITCODE -ne 0) { throw "scp failed: $LASTEXITCODE" } -& ssh -o BatchMode=yes -o ConnectTimeout=12 -i $Key $Remote ` - "powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\ytd_extdev_0903\incoming\_watch_agent8910.ps1" -if ($LASTEXITCODE -ne 0 -and -not $Once) { - # Ctrl+C 常非 0,不当作部署失败 - exit $LASTEXITCODE -} +& ssh.exe -o BatchMode=yes -o ConnectTimeout=12 -i $SshKey $SshHost ` + "powershell -NoProfile -ExecutionPolicy Bypass -File `"$IncomingLocalRun`"" +exit $LASTEXITCODE