5 Replies Latest reply on Nov 30, 2017 4:38 AM by Alexander Li

    SSH + Prompt not working when executing a command

    Alexander Li

      Hi everyone,

       

      I want to SSH to a server and execute command "tw_scan_control --list".

      When we execute that command, it will prompt asking for a password "Password:" as following picture:

      We set adapter request:

      [adapter request=

      <request-data>

        <ssh-request>

          <prompts>

            <prompt name="PromptPwd">Password:</prompt></prompts>

          <targets>

            <target name="">

              <host>10.250.200.63</host>

              <port>22</port>

              <userName>tideway</userName>

              <pass-phrase />

              <password>****MASKED****</password>

              <timeout-secs>60</timeout-secs>

              <use-shell-mode />

              <prompt />

              <establish-connection-timeout-secs>60</establish-connection-timeout-secs>

            </target>

          </targets>

          <commands>

            <command ignore-exit-code="true"><![CDATA[tw_scan_control --list]]></command>

            <command prompt="PromptPwd"><![CDATA[P@ssw0rd]]></command>

          </commands>

        </ssh-request>

      </request-data>]

       

      But failed and get timeout error:

      [adapter response=

      <ssh-command-output>

        <metadata>

          <status>success</status>

        </metadata>

        <targets-output>

          <target-output host="10.250.200.63">

            <metadata>

              <os-id>Linux</os-id>

              <os-version>2.6.32-642.6.1.el6.x86_64</os-version>

              <status>success</status>

            </metadata>

            <commands-output>

              <command-output>

                <metadata>

                  <status>error</status>

                  <error>Error executing command tw_scan_control --list. Error: Message[summary=Exception occurred in Adapter : TSelSSH. Error occurred parsing command results. ERROR : Message[summary=Exception occurred in Adapter :adapter terminal. Timeout occurred while connection for getting response data, detail=Exception occurred in Adapter :adapter terminal. Timeout occurred while connection for getting response data], detail=Exception occurred in Adapter : TSelSSH. Error occurred parsing command results. ERROR : Message[summary=Exception occurred in Adapter :adapter terminal. Timeout occurred while connection for getting response data, detail=Exception occurred in Adapter :adapter terminal. Timeout occurred while connection for getting response data]]</error>

                </metadata>

                <output />

              </command-output>

            </commands-output>

          </target-output>

        </targets-output>

      </ssh-command-output>]

       

      Anyone can help find my mistake?

       

      Thanks in advance,

      Alexander

        • 2. Re: SSH + Prompt not working when executing a command
          Ranganath Samudrala

          Your target does not have a prompt specified. So, when the adapter performs the login, what is it expecting parse before attempting to invoke the first command?

           

           

          Try the following:

           

           

               <target name="">

                  <host>10.250.200.63</host>

                  <port>22</port>

                  <userName>tideway</userName>

                  <pass-phrase />

                  <password>****MASKED****</password>

                  <timeout-secs>60</timeout-secs>

                  <use-shell-mode />

                  <prompt>$</prompt>

                  <establish-connection-timeout-secs>60</establish-connection-timeout-secs>

                </target>

          • 3. Re: SSH + Prompt not working when executing a command
            Alexander Li

            Hi Ranga, its not working.

             

            I change the [adapter request] to:

            <request-data>

              <ssh-request>

                <prompts>

                  <prompt name="initial">$</prompt>

                  <prompt name="passwordprompt">****MASKED****</prompt>

                </prompts>

                <targets>

                  <target name="">

                    <host>10.250.200.63</host>

                    <port>22</port>

                    <userName>tideway</userName>

                    <pass-phrase />

                    <password>****MASKED****</password>

                    <timeout-secs>60</timeout-secs>

                    <use-shell-mode />

                    <prompt />

                    <establish-connection-timeout-secs>60</establish-connection-timeout-secs>

                  </target>

                </targets>

                <commands>

                  <command prompt="initial"><![CDATA[tw_scan_control --list]]></command>

                  <command prompt="passwordprompt" ignore-exit-code="true"><![CDATA[P@ssw0rd]]></command>****MASKED****</commands>

              </ssh-request>

            </request-data>

             

            AO already able to see the prompt, but AO doesn't answer the prompt.

            [adapter response=

            <ssh-command-output>

              <metadata>

                <status>success</status>

              </metadata>

              <targets-output>

                <target-output host="10.250.200.63">

                  <metadata>

                    <os-id>Linux</os-id>

                    <os-version>2.6.32-642.6.1.el6.x86_64</os-version>

                    <status>success</status>

                  </metadata>

                  <commands-output>

                    <command-output>

                      <metadata>

                        <status>error</status>

                        <error>Error executing command tw_scan_control --list. Error: Message[summary=Exception occurred in Adapter : TSelSSH. Error occurred parsing command results. ERROR : Message[summary=Exception occurred in Adapter : AMP - Perform Action Executor - 1048:ssh:10.250.200.63:StreamReaderWithTimeOut. Message[summary=Exception occurred in adapter : AMP - Perform Action Executor - 1048:ssh:10.250.200.63:StreamReaderWithTimeOut. timeout (  60 secs) expired waiting for response with prompt: $. Data read so far:

            Password:

            null, detail=Exception occurred in adapter : AMP - Perform Action Executor - 1048:ssh:10.250.200.63:StreamReaderWithTimeOut. timeout (  60 secs) expired waiting for response with prompt: $. Data read so far:

            Password:

            null], detail=Exception occurred in Adapter : AMP - Perform Action Executor - 1048:ssh:10.250.200.63:StreamReaderWithTimeOut. Message[summary=Exception occurred in adapter : AMP - Perform Action Executor - 1048:ssh:10.250.200.63:StreamReaderWithTimeOut. timeout (  60 secs) expired waiting for response with prompt: $. Data read so far:

            Password:

            null, detail=Exception occurred in adapter : AMP - Perform Action Executor - 1048:ssh:10.250.200.63:StreamReaderWithTimeOut. timeout (  60 secs) expired waiting for response with prompt: $. Data read so far:

            Password:

            null]], detail=Exception occurred in Adapter : TSelSSH. Error occurred parsing command results. ERROR : Message[summary=Exception occurred in Adapter : AMP - Perform Action Executor - 1048:ssh:10.250.200.63:StreamReaderWithTimeOut. Message[summary=Exception occurred in adapter : AMP - Perform Action Executor - 1048:ssh:10.250.200.63:StreamReaderWithTimeOut. timeout (  60 secs) expired waiting for response with prompt: $. Data read so far:

            Password:

            null, detail=Exception occurred in adapter : AMP - Perform Action Executor - 1048:ssh:10.250.200.63:StreamReaderWithTimeOut. timeout (  60 secs) expired waiting for response with prompt: $. Data read so far:

            Password:

            null], detail=Exception occurred in Adapter : AMP - Perform Action Executor - 1048:ssh:10.250.200.63:StreamReaderWithTimeOut. Message[summary=Exception occurred in adapter : AMP - Perform Action Executor - 1048:ssh:10.250.200.63:StreamReaderWithTimeOut. timeout (  60 secs) expired waiting for response with prompt: $. Data read so far:

            Password:

            null, detail=Exception occurred in adapter : AMP - Perform Action Executor - 1048:ssh:10.250.200.63:StreamReaderWithTimeOut. timeout (  60 secs) expired waiting for response with prompt: $. Data read so far:

            Password:

            null]]]</error>

                      </metadata>

                      <output />

                    </command-output>

                  </commands-output>

                </target-output>

              </targets-output>

            </ssh-command-output

            • 4. Re: SSH + Prompt not working when executing a command
              Ranganath Samudrala

              Well this is progress, but the solution is not complete :-)

              1. You still do not have <prompt>$<prompt> in the target.

              2. The below is incorrect:

                  <commands>

                    <command prompt="initial"><![CDATA[tw_scan_control --list]]></command>

                    <command prompt="passwordprompt" ignore-exit-code="true"><![CDATA[P@ssw0rd]]></command>****MASKED****</commands>

                </ssh-request>

               

               

              The commands XML should be:

              <commands>

                 <command prompt="passwordprompt"><![CDATA[tw_scan_control --list]]></command>

                 <command prompt="initial" ignore-exit-code="true"><![CDATA[P@ssw0rd]]></command>

              </commands>

               

               

              You may even have to use ignore-exit-code in the first command.

              • 5. Re: SSH + Prompt not working when executing a command
                Alexander Li

                Thanks Ranga. Now the solution is working =).