Daniel Super Contributor.
Super Contributor.
751 views

SSH Shell and mutiple lines

Jump to solution

I'm trying to use the SSH shell operation to send some commands

send bash
expect .*
send ${echo_command}
expect .*

The problem is tha the echo_command has a lot of break lines

Foe example, something like this.

echo "Test 
123
234
567" > /tmp/test

The problem is that OO doesn't like the line breaks.

I get something like this:

{exception=com.hp.oo.content.ssh.exceptions.SSHException: java.lang.Exception: unsupported operation: Script:currently on line: 4
1 send bash2 expect .*3 send echo "echo "Test 4 123 5 234 6 567" > /tmp/test" > /tmp/test expect .*
	at com.hp.oo.content.ssh.services.impl.SSHServiceImpl.runExpectCommand(SSHServiceImpl.java:252)
	at com.hp.oo.content.ssh.actions.SSHShell.runSshExpectCommand(SSHShell.java:115)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at com.hp.oo.sdk.plugins.abstracts.BaseActionPlugin.execute(BaseActionPlugin.java:53)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	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:97)
	at sun.reflect.GeneratedMethodAccessor527.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at io.cloudslang.worker.execution.reflection.ReflectionAdapterImpl.executeControlAction(ReflectionAdapterImpl.java:62)
	at io.cloudslang.worker.execution.services.ExecutionServiceImpl.executeStep(ExecutionServiceImpl.java:326)
	at io.cloudslang.worker.execution.services.ExecutionServiceImpl.execute(ExecutionServiceImpl.java:80)
	at io.cloudslang.worker.management.services.SimpleExecutionRunnable.executeRegularStep(SimpleExecutionRunnable.java:167)
	at io.cloudslang.worker.management.services.SimpleExecutionRunnable.run(SimpleExecutionRunnable.java:120)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at io.cloudslang.worker.management.services.WorkerThreadFactory$1.run(WorkerThreadFactory.java:33)
	at java.lang.Thread.run(Thread.java:745)

I bolded and underlined the steps to be more visible.

There is any way to save the line breaks or to make literal the text I need to add?

0 Likes
1 Solution

Accepted Solutions
Daniel Super Contributor.
Super Contributor.

Re: SSH Shell and mutiple lines

Jump to solution

Jarod, thank you very much for your help. Usually in IT, we try to find a solution and sometimes its not the easiest. So I tried to take a look to the whole thing.

Basically the flow involves, requesting the information and installing the certificate 😛
When I add the certificate as an input it adds spaces and then I change it to new lines (\n). I run some filters to have the certificate ready to install (to replace the spaces with newlines).
Instead of adding the new lines, I change it to ---newline---.

I wrote that file on the F5 and after that I make a sed to replace ---newline--- with a \n

I was able to do it the first try using SSH Shell

0 Likes
7 Replies
Outstanding Contributor.. JarodMB Outstanding Contributor..
Outstanding Contributor..

Re: SSH Shell and mutiple lines

Jump to solution

What about using printf instead of echo? 

printf "Test\n123\n234\n567"

 

0 Likes
Daniel Super Contributor.
Super Contributor.

Re: SSH Shell and mutiple lines

Jump to solution

Well, basically the text I need to write is a certificate. I didn't put it in the original post to explain the problem I'm having with SSH Shell

For example:

-----BEGIN CERTIFICATE-----
MIIDBTCCAe2gAwIBAgIJAPCwOYWI8Yw6MA0GCSqGSIb3DQEBBQUAMBkxFzAVBgNV
BAMMDnd3dy5kYW5pZWwuY29tMB4XDTE4MDYwOTEzNTEyOFoXDTI4MDYwNjEzNTEy
OFowGTEXMBUGA1UEAwwOd3d3LmRhbmllbC5jb20wggEiMA0GCSqGSIb3DQEBAQUA
A4IBDwAwggEKAoIBAQDZjp9SarcpJMgC/mlVNIr5irZWM5APjURmvuKkfyjgFOvT
QTEN35l7j6ZVeWvKKa0stgHWIzYKVFFcBYD90a5De/EfeACRyau1LbH9yyq2ArWq
6p5U8vWE6zyC13ISExbY3wuYTQlHsiCx+7fA59VqAHNv4VBBtIhJm6yFt5CKT7Wj
scj7G5WGI11PF5S/WKkw+q69MxGm5Y8hQU5QEnz8DyVztWRh9aacCydiD5PdPjvU
tFuXNZBlVyWiwegytAD74oir7VRXd5W6a+/w+8x/LDor4HO8sR7mnX9/xn8zOTLx
3KaQb+KZEfWWJw38coQ0aNfLduUaU6AscSUHyj0JAgMBAAGjUDBOMB0GA1UdDgQW
BBTGDY1tbSeAlf80WPhZABNNqtlwnDAfBgNVHSMEGDAWgBTGDY1tbSeAlf80WPhZ
ABNNqtlwnDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQCfiOkN6Mdr
PkDbqGq05d7sxtGRTPmu+mXAHcfUNGe0ccvmROF8+Ia6mNzKo/kUY1HS6/5Yvue3
JxL4VQzFDbZ1ECSfaxAiuSdQeg2BiVgOk4va1Jjn7c4GO5mTuROBhgMUs5cln7pM
ayYRUgynBAhxK0zyeCkdT0LAGcbZVF8zdRKJt4z75l80PMKA/1eQbr0k4RdBNsA/
vsKas5dw1FiigzoDSGqAFWFOSf2cWGa7wq/3015a3gvabpMC3gbVE1Xcf9kXrBw3
pW2i5fl038JPraMBV0AZJaMTVDNv4X/+VzRjv0JZFcUDJWcTKXUmy7iLA16gfVAh
Gf4UU7Pn8+jw
-----END CERTIFICATE-----

So using something as printf its the same, because the SSH Shell will get the certificate this way.

Using the SSH Command operation works, but I need to run a previous command before the echo.

0 Likes
Outstanding Contributor.. JarodMB Outstanding Contributor..
Outstanding Contributor..

Re: SSH Shell and mutiple lines

Jump to solution

What about something like below in a command

firstcommand; if [ $? == 0 ]; then echo certstring >> file else echo fail fi

0 Likes
Daniel Super Contributor.
Super Contributor.

Re: SSH Shell and mutiple lines

Jump to solution

Well, it was a good option, but it didn't work sorry.

So, I'm trying to import the certificate to the Big IP/F5. If you are familiar with F5 BigIP, they have a tmsh. Its a shell that let you use the F5 commands. In our test environment worked, because the user logged in with bash by default and changed totmsh, but the real environment is configure inverse. You login with tmsh by defualt and need to change to bash.

Basically to leave tmsh you need to write bash, to be able to use echo.

When I tried the command, it gave an error after the bash command.

So I need the shell command and need to find a way to encapsulate the certificate

0 Likes
Outstanding Contributor.. JarodMB Outstanding Contributor..
Outstanding Contributor..

Re: SSH Shell and mutiple lines

Jump to solution

what about something like 

send bash
expect .*
send cat << EOF > tempfile
[certContent]
EOF
expect .*
send var=$(cat tempfile)
expect .*
..... then use how you would in the command using the $var in place of the contents to be echoed 

Daniel Super Contributor.
Super Contributor.

Re: SSH Shell and mutiple lines

Jump to solution

Jarod, thank you very much for your help. Usually in IT, we try to find a solution and sometimes its not the easiest. So I tried to take a look to the whole thing.

Basically the flow involves, requesting the information and installing the certificate 😛
When I add the certificate as an input it adds spaces and then I change it to new lines (\n). I run some filters to have the certificate ready to install (to replace the spaces with newlines).
Instead of adding the new lines, I change it to ---newline---.

I wrote that file on the F5 and after that I make a sed to replace ---newline--- with a \n

I was able to do it the first try using SSH Shell

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: SSH Shell and mutiple lines

Jump to solution

Did you try...

cat <<EOF > /tmp/test
${certstring}
EOF

Note:  The trailing "EOF" must be the only thing on the line, followed by a carriage return.  Or, if you have the text "EOF" in your string, you can use any string for the delimier.. like:

cat <<@@@ > /tmp/test
stuff
@@@
echo it worked

This won't work on windows but you're using unix so...

 

<edit> - looks like Jarod beat me to it 🙂 </edit>

 

Tags (1)
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.