title: Automate connection and command execution on different linux machines via Shell script
body: <p>Hi<br>I am working with shell scripting language (I am new to it). I have 6 different linux machines. I have access to machine A. Through machine A and using <code>ssh -l &lt;username&gt; &lt;ip_address&gt;</code>, I can connect to B. B has access to C, D, and E only (A cant access them directly. It has to do so via B only). Similarly, F is accessible only via C.</p>
  
  <p>I have to run certain commands on all the linux machines (for eg, <code>pwd</code> and <code>ls -lrt</code>) from my system "A". How can I automate that thing? I mean is it possible in this scenario to execute script on machine A, which itself connects to all other machines as shown in figure and give me output of commands executed (via script only) on all machines as a text file in machine A?</p>
  
  <p>I wrote a shell script. On execution of this script on machine A, it connects to machine B. And then, nothing more happens i.e. rest of the script is not executed. When I press <code>Ctrl + D</code> on machine B, script again starts executing. That is my problem because it is executing commands on machine A only, nothing on machine B. I want the script to keep running even thought the machine is now changed. What i feel the problem is, the machine B has no access to script. So, I need a workaround for how to do that.
  <br><br>
  If it is not possible in shell, which scripting language will be good for what I want to do?</p>
  
  <p>I googled but the search results are not what I am looking for :(
  <img src="https://i.stack.imgur.com/jFL7J.png" alt="enter image description here"></p>