Script Syntax: Expect=Keyword
- Last Updated: December 11, 2024
- 2 minute read
- WhatsUp Gold
- Version 2024
Expect=Keyword gives you flexibility to accept variable responses and pick out crucial information using special control characters and regular expressions. If you do not need flexibility, or are new to writing your own custom TCP/UDP scripts, you may want to use the SimpleExpect keyword.
There are 4 variations of the Expect Keyword:
- Expect. Returns true when the expected value is matched.
- Expect(MatchCase). Only returns true when the case matches the expected value.
- DontExpect. Returns true when the value is not found.
- DontExpect(MatchCase). Returns true when the value is not found.
The Expect syntax is Expect=Response, where the Response
is either specified as an exact text string, or a mixture of regular expression rules and text. The
Add/Edit Expect Rule button helps you construct and test a
regular expression response string. It automatically chooses the variation of Expect for
you based on options you select.
WhatsUp Gold v7 or v8 users: The ~, ^,
! and = = codes have been replaced with variations
on the Expect keyword itself. Migrated definitions are automatically converted.
Example
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
Example
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
Example
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