title: In ruby, I want to do a SSH connection and then perform "telnet 0" without the port and then finally a telent command grep Power
body: <p>I am writting a automation test where I have to first start a SSH session, then enter telnet 0 and connect to that session using credentials and then finally inputting a command grep power and capturing the response to validate.
  I tried two methods::
  1)</p>
  <pre><code>Net::SSH.start(IP,
                    Username, 
                    :password =&gt; Password) do |ssh|
  
  ssh.exec!(&quot;telnet 0&quot;)
  
    //login to telnet and perform the command
  ssh.close
  end
  </code></pre>
  <p>This one didnt work for me</p>
  <p>2)</p>
  <pre><code>loginInfo = {&quot;Name&quot; =&gt; 'telnetUsername',
                              &quot;Password&quot; =&gt; 'telnetPassword',
                              &quot;LoginPrompt&quot; =&gt; /Username:/
                          }
          
  begin
      #Define the gateway.
          objGateway = Net::SSH::Gateway.new(IP, 
                                              'SSHUsername', 
                                              :password =&gt; 'SSHPassword')
      rescue Exception =&gt; e
          
          next
      end
  
      #Open the telnet port.                          
          objLocalPort = objGateway.open(&quot;localhost&quot;, telnetPort)
          
      #Create telnet connection passing in the previously opened port.
      objTelnet = Net::Telnet::new(&quot;Host&quot; =&gt; &quot;127.0.0.1&quot;, 
                                  &quot;Port&quot; =&gt; objLocalPort)
      #Do the telnet login.
      objTelnet.login(loginInfo)
  objTelnet.cmd(&quot;grep power&quot;)
  </code></pre>
  <p>Now I am stuck with this one becaues I dont have a port to give in objLocalPort</p>
  <p>If something can be modified to the above solution is greatly appreciated, or if there is something different can you please help with that and explain as well.
  Thank You</p>