Super Contributor.. Giulio Soleni Super Contributor..
Super Contributor..
4146 views

SSH Shell Operation - how should I define the command?

Hi everybody,

I am dealing with "SSH Shell" Operation trying to figure out how could I use it in a flow for my purposes...

I am not sure I understood how the "command" input should be specified.

From the description of the operation I read:

command - The commands to execute. This should be made up of 'send <command>' and 'expect <regular expression>' statements separated by newlines.

But from a flow of example (available within the installation) SSH Shell Session Sharing Example I am not able to understand how the "expect" part of the command are used.

For example, I see that in the example flow, the first occurence of the SSH Shell step has the following command (in 3 lines):

expect (.*\s*)*?
send export HPOO=yes
expect (.*\s*)+[\$#]$

 

Why does it start with an expect??

and what should be supposed to match the 1st regex (.*\s*)*? ... ??

 

Any help would be appreciated.

Thank you in advance

 

Giulio

Labels (1)
Tags (1)
0 Likes
8 Replies
Daniel_Linsley Absent Member.
Absent Member.

Re: SSH Shell Operation - how should I define the command?

expect (.*\s*)*?   Will match anything.  Any character, any whitespace, 0 or more occurances.

 

The next expect will do the same thing, but expect the end of the line to have either a "$" or "#"

 

Dan.

0 Likes
Absent Member.. ntt00015 Absent Member..
Absent Member..

Re: SSH Shell Operation - how should I define the command?

Hi,

 

Let me try to explain over an example :

I want to run "cd somefolder" command and after that, I want to run "ls" command. For third execution "ps" command.

[root@system]/root> cd /Central-9.00
[root@system]Central-9.00>

 

[root@system]Central-9.00>ls -ltr

[root@system]Central-9.00>

 

[root@system]Central-9.00>ps -ef

[root@system]Central-9.00>


In OO I have to send commands as below:

send cd /Central-9.00
expect (.*\s*)*/Central-9.00>
send ls -ltr
expect (.*\s*)*/Central-9.00>
send ps -ef

 

For multi command executions you have to send one command and then wait for system to execute your command. If you don't use "expect" OO can't  understand  when to send following command. "expect" is being used for this. In the example we are telling the system send the commands when we see the bash prompt.

 

I hope it will be helpful.

 

Regards.

 

0 Likes
Absent Member.. ntt00015 Absent Member..
Absent Member..

Re: SSH Shell Operation - how should I define the command?

In addition expect (.*\s*)*? is regular expression. It uses regular expression for finding the search string.
In our prompt line it writes $ or # , so we replace "?" with our prompt line character. expect (.*\s*)*#
After the command execution it searches in the output if it # occurs then sends the following command.
0 Likes
Rakesh_Katpally Absent Member.
Absent Member.

Re: SSH Shell Operation - how should I define the command?

There is no need for using "expect (.*\s*)*/Central-9.00>". All you can do is use

 

expectendswith >

 

that should do it

0 Likes
Absent Member.. AlexGg Absent Member..
Absent Member..

Re: SSH Shell Operation - how should I define the command?

If you prefer to use just UNIX command directly you can use operations 'SSH Command'
0 Likes
Raju1990
Visitor.

Re: SSH Shell Operation - how should I define the command?

Hi,

Thanks for the solution in continouation with above i have query i.e

actually i need to pass command like agentid count 500 then it displays 500 agentid's.

in this i need to get only one id by pressing F7. How can i get this.

here i am trying like this 

send list agent-loginID 6210000 count 500
expect (.*\s*)*?/AGENT LOGINID 
send F7
expect (.*\s*)*?/AGENT LOGINID

pls correct me.Thanks in advance.

0 Likes
Raju1990
Visitor.

Re: SSH Shell Operation - how should I define the command?

HI,

How can i pass function key F7 as a command throuh SSH Shell.

Can any one help me how to achieve this.

Thanks,

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: SSH Shell Operation - how should I define the command?

Have you tried with the escape secuence?

send ^[[18~

 or get which is the escape secuence for function keys on your case with

tput kf7

you can also try with ssh wizard

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.