title: Ruby, run linux commands one by one, by SSH and LOG everything
body: <p>I want to write code in Ruby witch net::ssh that run commands one by one on remote linux machine and log everything (called command, stdout and stderr on linux machine).</p>
  
  <p>So I write function:</p>
  
  <pre><code>  def rs(ssh,cmds)
      cmds.each do |cmd|
        log.debug "[SSH&gt;] #{cmd}"
        ssh.exec!(cmd) do |ch, stream, data|    
          log.debug "[SSH:#{stream}&gt;] #{data}"            
        end  
      end
    end
  </code></pre>
  
  <p>For example if I want to create on remote linux new folders and file: "./verylongdirname/anotherlongdirname/a.txt", and list files in that direcotry, and find firefox there (which is stupid a little :P) so i call above procedure like that:</p>
  
  <pre><code>Net::SSH.start(host, user, :password =&gt; pass) do |ssh|  
  
    cmds=["mkdir verylongdirname", \                                 #1
          "cd verylongdirname; mkdir anotherlongdirname, \           #2
          "cd verylongdirname/anotherlongdirname; touch a.txt", \    #3
          "cd verylongdirname/anotherlongdirname; ls -la", \         #4
          "cd verylongdirname/anotherlongdirname; find ./ firefox"   #5 that command send error to stderr.
          ]
  
    rs(ssh,cmds)   # HERE we call our function
  
    ssh.loop
  end
  </code></pre>
  
  <p>After run code above i will have full LOG witch informations about executions commands in line #1,#2,#3,#4,#5. The problem is that state on linux, between execude commands from cmds array, is not saved (so I must repeat "cd" statement before run proper command). And I'm not satisfy with that.</p>
  
  <p>My purpose is to have cmds tables like that:</p>
  
  <pre><code>  cmds=["mkdir verylongdirname", \     #1
          "cd verylongdirname", \        
          "mkdir anotherlongdirname", \  #2
          "cd anotherlongdirname", \
          "touch a.txt", \               #3
          "ls -la", \                    #4
          "find ./ firefox"]             #5
  </code></pre>
  
  <p>As you see, te state between run each command is save on the linux machine (and we don't need repeat apropriate "cd" statement before run proper command). How to change "rs(ssh,cmds)" procedure to do it and LOG EVERYTHING (comand,stdout,stdin) like before?</p>