• 0
Sign in to follow this  
Joe Tran

Groovy Expect Scripting -- "]$" prompts

Question

Most of the Linux environments I work with are RHEL or CentOS and our prompts look like: 

[username@hostname ~]$

I can't seem to find a prompt pattern that works for both the closing square bracket and the dollar sign when writing a script using the com.santaba.agent.groovyapi.expect.Expect package. No amount of escaping seems to work like '\\]\\$' or ']\\$'. I do need the multi-character prompt because the output I want to parse will include errant $, but not ]$. 

Multi-character prompts are generally not a problem because I often have to expect a sudo password prompt using a 'username:' pattern and this works without issue. 

Any ideas on how to tackle this?

 

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 1

@Joe Tran you were close, you should be able to match it with this:

'\\[.*\\]\\$'

The expect() method actually takes a Java Pattern which is compiled down to a Regex object.

You can see if your Pattern converts to the expected Regex by using:

println Pattern.compile('yourpatternstring')

We should really add a method that takes a plain old regex, sorry for any confusion. Let me know if the above doesn't work for you.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this