I want to write code in Ruby witch net :: ssh that runs commands one after another on a remote Linux computer and writes everything (called a command, stdout and stderr on a linux machine).
So, I am writing a function:
def rs(ssh,cmds) cmds.each do |cmd| log.debug "[SSH>] #{cmd}" ssh.exec!(cmd) do |ch, stream, data| log.debug "[SSH:#{stream}>] #{data}" end end end
For example, if I want to create new folders and a file on remote linux: "./verylongdirname/anotherlongdirname/a.txt" and list the files in this directory and find firefox there (which is a bit stupid: P), so I call the similar procedure above:
Net::SSH.start(host, user, :password => pass) do |ssh| cmds=["mkdir verylongdirname", \
After executing the above code, I will have full information about the command files about the execution commands in lines # 1, # 2, # 3, # 4, # 5. The problem is that the state in linux between execude commands from the cmds array is not saved (therefore I have to repeat the "cd" instruction before running the appropriate command). And I am not satisfied with this.
My goal is to have these cmds tables:
cmds=["mkdir verylongdirname", \ #1 "cd verylongdirname", \ "mkdir anotherlongdirname", \ #2 "cd anotherlongdirname", \ "touch a.txt", \ #3 "ls -la", \ #4 "find ./ firefox"] #5
As you can see, the te state between the start of each command is saved on the linux machine (and we do not need to repeat the appropriate "cd" instruction before running the corresponding command). How to change the procedure "rs (ssh, cmds)" to do this, and LOG ALLVER (comand, stdout, stdin), as before?