Highlighted
Honored Contributor.
Honored Contributor.
162 views

expectEndsWith Regex

Hi,

I have to execute a list of commands In /Base [1.10.0]/Library/Operations/Remote Command Execution/SSH/v1.0/SSH Shell operation.

The issue is that, in the third command,  the server (which runs the commands) can return one of two responses:

either:

 ...................................enter a command>

or:

....................................please enter your password:

My question: how to match the two responses in the same expectEndsWith regex ?

Thanks in advance.

0 Likes
2 Replies
Highlighted
Respected Contributor.
Respected Contributor.

Re: expectEndsWith Regex

Hi,

You can use below syntax - 

expect {
"enter a command"  {send "comanad;exp_continue}
"password:"  {send "password\r";exp_continue}
-re $prompt
}

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

expectEndsWith Regex

Thanks AB but it does not work:

unsupported operation: Script:currently on line: 6
1 expect (.*\s*)*?
2 send something
3 expectEndsWith >
4 send something
5 expect {
6 "Username:"
7 {
8 Do Something
16 }
17 "Password"
18 {
19 Do Other
23 }
24 }

at com.opsware.pas.content.commons.shell.simulator.ScriptModel.parseScript(ScriptModel.java:76)
at com.opsware.pas.content.commons.shell.simulator.ScriptModel.<init>(ScriptModel.java:19)
at com.opsware.pas.content.commons.shell.simulator.ScriptRunner.<init>(ScriptRunner.java:50)
at com.opsware.pas.content.commons.shell.simulator.ScriptRunner.<init>(ScriptRunner.java:85)
at com.opsware.pas.content.commons.shell.simulator.ScriptRunner.<init>(ScriptRunner.java:106)
at com.opsware.pas.content.commons.shell.simulator.ShellSimulator.<init>(ShellSimulator.java:106)
at com.iconclude.content.actions.ssh.SSHShell.execute(SSHShell.java:128)
at sun.reflect.GeneratedMethodAccessor490.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.hp.oo.sdk.plugins.abstracts.BaseActionPlugin.execute(BaseActionPlugin.java:53)
at sun.reflect.GeneratedMethodAccessor489.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.hp.oo.maven.PluginAdapterImpl.executePlugin(PluginAdapterImpl.java:328)
at com.hp.oo.maven.PluginAdapterImpl.execute(PluginAdapterImpl.java:248)
at com.hp.oo.execution.control.actions.contentexecution.ContentExecutionActions.executeContentAction(ContentExecutionActions.java:96)
at sun.reflect.GeneratedMethodAccessor428.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.hp.score.worker.execution.reflection.ReflectionAdapterImpl.executeControlAction(ReflectionAdapterImpl.java:71)
at com.hp.score.worker.execution.services.ExecutionServiceImpl.executeStep(ExecutionServiceImpl.java:324)
at com.hp.score.worker.execution.services.ExecutionServiceImpl.execute(ExecutionServiceImpl.java:86)
at com.hp.score.worker.management.services.SimpleExecutionRunnable.executeRegularStep(SimpleExecutionRunnable.java:156)
at com.hp.score.worker.management.services.SimpleExecutionRunnable.run(SimpleExecutionRunnable.java:120)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at com.hp.score.worker.management.services.WorkerThreadFactory$1.run(WorkerThreadFactory.java:41)
at java.lang.Thread.run(Thread.java:745)

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.