CQE Repository Script Management Guide
Learn how to manage, execute, and monitor script registration in the CQE (Custom Query Engine) Repository.
📋 Overview
The CQE Repo List provides a centralized repository for your maintenance and diagnostic scripts. You can store scripts once and deploy them across any number of logical servers (LSVR) with custom execution parameters.
🔍 Script Details & Execution
When you click on a script in the list, the detail modal opens with the following capabilities:
1. Script Content
View the full source code of the script. This is read-only in the list view; use the edit feature if modifications are needed.
2. Execution Settings (NEW)
Before registering a script to a server, you can configure how it should run:
- Active: Toggle whether the script is enabled for the selected servers.
- Repeat: If enabled, the script will run periodically.
- Interval (min): Set the frequency for repeated execution (in minutes).
- Start Date: Specify when the first execution should occur.
3. Server Registration (LSVR Queue Put)
You can select one or more servers from your current project to receive this script.
- LSVR Selector: Use the checkboxes to choose target servers.
- Add to Queue: Click this button to register the script with the defined settings for all selected servers.
📊 Script Usage Status
At the bottom of the modal, the Usage Status Table displays all servers currently registered for this specific script.
- Hostname: The name of the server using the script.
- Usage: The logical server's defined purpose.
- Settings: View the active/repeat/interval status for each registration.
- Last Run: Tracks the last time the script was successfully executed on that machine.
API 參考
有關此功能的 API 詳細規範,請參閱專用指南。
疑難排解
| 症狀 | 原因 | 解決 |
|---|---|---|
| 加入佇列後腳本仍未執行 | 執行設定中 啟用 (Active) 處於關閉狀態 | 在詳細視窗中開啟 Active,然後重新加入佇列。 |
| LSVR 選擇器中看不到目標伺服器 | 目前所選專案沒有伺服器,或伺服器屬於其他專案 | 確認已在頂部選擇正確的專案。 |
| 重複執行未生效 | 已開啟 重複 (Repeat),但 間隔 (分鐘) 為空 | 將間隔設定為 1 或更大後重新註冊。 |
| 使用狀況中的 最後執行 未更新 | 目標伺服器的代理尚未接收到佇列 | 檢查代理連線狀態以及開始時間是否為過去時刻。 |
🔌 CQE API (自動化)
上述介面操作對應以下 CQE API 動詞(byAK/bySk 分派器)。請求傳送 text(動詞+參數名)、jsondata(值)與 token。
-
CQERepoPut
msName msDetail msBody msPer msPrice msType— 將指令碼註冊到儲存庫。text只攜帶 參數名稱:CQERepoPut msName msDetail msBody msPer msPrice msTypejsondata攜帶實際的值:{"msName":"...","msDetail":"...","msBody":"#!/bin/sh\n...","msPer":0,"msPrice":0,"msType":"sh"}msType限制為 5 個字元(varchar(5))。像powershell、expect或cmdwin這類較長的名稱無法儲存 — 請使用下表中的簡短代碼。
msType 目標作業系統 代理實際的執行方式 ps1Windows powershell.exe(無視窗)cmdWindows cmd.exebatWindows 正規化為 cmd,再以cmd.exe執行wsfWindows wscript.exe //B //Nologops1ui/cmduiWindows 在桌面工作階段中以可見視窗執行 shLinux sh <tempfile>pyLinux python3 <tempfile>ps1Linux pwsh <tempfile>請勿混用作業系統。 Windows 代理只會執行上述的 Windows 類型;其他任何值都會被記錄為
unsupported_script_type並且 不會執行。Linux 代理則相反 — 它會 把所有未知的類型都交給sh執行,因此將bat/wsf指令碼指派給 Linux 伺服器時,會在無任何提示的情況下以sh執行而失敗。請以你要指派的那些伺服器的作業系統相符的類型來註冊指令碼。-
註冊 Linux shell 指令碼: 在
msType填入sh,並將完整的 shell 指令碼放入msBody。Linux 代理會將內容寫入暫存檔並 以sh執行,因此#!/bin/bashshebang 會被忽略。請避免只有 bash 才支援的語法([[ ]]、陣列等),改以 POSIX shell 撰寫;或是在第一行用exec bash "$0" "$@"交棒給 bash。#!/bin/sh # Runs under sh, so use POSIX syntax only. sk/lssn/apiaddrv2 arrive as environment variables. curl -s -H "Authorization: Bearer $sk" "$apiaddrv2/health" | jq -r .status -
指令碼內容要放在哪裡: 兩種做法都可行。
- 把完整內容放進
msBody— 主機上不需要預先安裝任何東西,而且在 giip 端的變更會推送到每一台伺服器。建議採用。 - 把指令碼留在主機上,只去呼叫它 — 適用於本來就需要
jq/curl等前置條件的主機,或是內容非常長的情況。此時你必須自行追蹤各主機的部署狀態。 msBody為ntext,因此實際上沒有長度限制(觀測到的最大值: 20,883 個字元)。
- 把完整內容放進
-
CQEQueuePut
mssn lssngroup csn interval active script_type custom_values repeat startdate auid— 將指令碼指派到伺服器。lssngroup: 逗號分隔的 LSSN 清單(每台伺服器一筆指派)。interval: 分鐘。repeat: 0/1 = 一次性, 2 = 遞迴(每隔 interval 重複)。custom_values: 依伺服器注入的值 → 取代指令碼內容中的{{CustomVariables}}。
-
CQEQueueGet
lssn hostname os op— 代理輪詢以接收下一個指令碼內容。
指令碼內容佔位符: {{CustomVariables}}(每次指派的 custom_values,伺服器端注入)、{{sk}}(代理權杖)、{{lssn}}(代理 LSSN)。
Linux 代理還會把
sk、lssn與apiaddrv2匯出 為環境變數。你可以不用{{sk}}/{{lssn}}佔位符,而直接參照$sk、$lssn與$apiaddrv2。
執行限制
| Windows 代理 | Linux 代理 | |
|---|---|---|
| 時間限制 | 預設 600 秒;可用 giipAgent.cfg 中的 cqetimeoutsec 變更。超過時指令碼會被終止 | 無 |
| 執行方式 | 暫存檔、無視窗行程 | 暫存檔,以 sh 執行 |
| 內容長度 | 無限制(ntext) | 同上 |
執行間隔: interval 以分鐘為單位。實際的執行頻率由代理的輪詢週期決定 — interval=0 不是 指「沒有排程」,而是指 每一輪輪詢輪替時都重新派送。多個啟用中的佇列會以輪替方式處理,因此在有 N 個佇列時,感受到的間隔會延長到大約 N 倍(於 giipdb docs/30_Specs/SPEC_AND_CHECKLIST.md 中實測)。把間隔設為 1 分鐘並不會讓它執行得比輪詢週期更頻繁。
結果儲存在哪裡: 指令碼的 stdout/stderr 會寫到 執行代理的那台伺服器上的本機記錄檔。只有 摘要 會傳送到 giip — 一次 KVSPut(kType=lssn、kKey=<lssn>、kFactor=giipagent)會建立一筆 event_type="script_execution" 記錄,其中保存 script_type、exit_code、execution_time_seconds、mslsn 與 mssn。輸出本身不會儲存在 giip。 若要在 giip 中看到輸出,請讓指令碼用 KVSPut 發佈(保留期限則依該 KVS 設定)。
失敗通知: 沒有內建的通知。請以查詢 exit_code 非零的 script_execution 記錄來偵測失敗,或是從指令碼內部發送警報。
完整規格: giipdb
docs/30_Specs/CQE_SPECIFICATION.md。
Version: 1.3
Last Updated: 2026-10-19
Source File: giipv3/public/help/cqerepolist.en.md