指令碼語法:Expect=Keyword
- Last Updated: October 16, 2024
- 3 minute read
Expect=Keyword 可讓您彈性接受可變回應,並利用特殊控制字元和規則運算式找出重要資訊。若您不需要彈性或才剛開始撰寫自訂的 TCP/UDP 指令碼,可使用 SimpleExpect 關鍵字。
Expect 關鍵字有 4 種變化:
- Expect :符合預期值時傳回 true。
- Expect(MatchCase) :只在大小寫符合預期值時傳回 true。
- DontExpect :找不到值時傳回 true。
- DontExpect(MatchCase) :找不到值時傳回 true。
Expect 語法是
Expect=Response
,其中 Response 不是指定的完整文字字串,就是混合
規則運算式規則
和文字。
[加入預期值規則]/[編輯預期值規則]
按鈕可讓您建構、測試規則運算式回應字串。系統會根據您選取的選項,自動選擇 Expect 的變化。
WhatsUp Gold v7 或 v8 使用者:
~
、
^
、
!
和
=
= 代碼已經被 Expect 關鍵字的變化所取代。系統會自動轉換已經移轉的定義。
範例 1:
#
# Note: script comments start with a # character
#
# Send a simple text command
#
Send = Hello There
#
# Expect a nice response that begins with, "Hi, How are you"
#
Expect=^Hi, How are you
範例 2:
#
# Send a command followed by CR/LF
#
Send=Select * from Accounts\r\n
#
# Expect a large response, but we only care to check that somewhere
# in the response John Doe is mentioned
#
Expect=John Doe
範例 3:
#
# Send a binary escape (27) and an x y and z and then a nak (21)
#
Send=\x1Bxyz\x15
#
# Expect something that does *not* contain 123 escape (27)
#
DontExpect=123\x1B