Ruby Net::SSH Change directories using variable interpolation
exec, ruby, ssh
Solution
The problem is that Net::SSH uses a different shell for each exec call. The solution is to use stateful shell. There is a gem to do this, but it is outdated. Net::SSH::Shell via https://github.com/mitchellh/net-ssh-shell
I chose to use Rye to handle this task. http://code.google.com/p/rye/
Problem
I am fairly new to Ruby, so please forgive me if I am missing something obvious. The problem is that Ruby doesn't seem to be doing variable interpolation in the Net::SSH.exec! method. ``` VCL_DIR = "/usr/local/etc/varnish/" host = '0.0.0.0' Net::SSH.start(host, 'root') do |ssh| puts "Changing directories to #{VCL_DIR}" ssh.exec!("cd #{VCL_DIR}") res = ssh.exec!("pwd") puts "Server reports current directory as #{res}" end ``` Output: ``` Changing directories to /usr/local/etc/varnish/ Server reports current directory as /root ``` Any help is appreciated. Using Ruby 1.9.3p194