スクリプトの構文:Expect= キーワード
- Last Updated: October 16, 2024
- 3 minute read
Expect= キーワードを使用すると、さまざまな応答を受け入れ、特殊な制御文字と正規表現を使用して重要な情報を柔軟に選別することができます。柔軟性が不要な場合や、独自のカスタム TCP/UDP スクリプトを初めて記述する場合は、 SimpleExpect キーワードの使用をお勧めします。
Expect キーワードには次の 4 種類があります。
- [予想] 。期待される値が一致するときに true を返します。
- Expect(MatchCase) 。大文字と小文字の区別が期待される値と一致するときにのみ true を返します。
- DontExpect 。値が見つからないときに true を返します。
- DontExpect(MatchCase) 。値が見つからないときに true を返します。
Expect 構文は
Expect=Response
で、Response は正確なテキスト文字列または
正規表現ルール
とテキストの組み合わせで指定します。
[Expect ルールの追加/編集]
ボタンは、正規表現の応答文字列の構成とテストに役立ちます。選択したオプションに基づいて、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