title: BASH - log into a server and then another server
body: <p>I'm writing a script to log into a gateway server and from the gateway server to the nodes that only have access through the gateway</p>
  
  <p>My script looks like:</p>
  
  <pre><code>#!/bin/bash
  
  cool () {
      ssh -A SERVER &lt;&lt; EOF
      ls -l
  EOF
  }
  
  
  fool () {
      ssh -A GATEWAY &lt;&lt; EOF
          touch foobar
          $(cool)
  EOF
  }
  
  export -f cool
  export -f fool
  
  fool
  </code></pre>
  
  <p>So what ends up happening is that I log into the GATEWAY, and run a few commands. 
  Then when I call the function "cool" to ssh into the node, it does that but then starts reading the message from the splash screen and executing the command which is incorrect. 
  I want it to execute "ls -l" in the function cool!</p>
  
  <p>Oh and getting rid of the splash screen isn't an option!</p>