0

I am trying to execute a rake task using python's paramiko module.

I have the following code:

ssh_client = paramiko.SSHClient()
ssh_client.load_system_host_keys()
ssh_client.connect(myserver, username="root")
ssh_stdin, ssh_stdout, ssh_stderr = ssh_client.exec_command("cd /mnt/app-production/current ; export PATH=/usr/local/rubies/1.9.2-p320/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games ; bundle exec rake images:load_swatch")
print ssh_stdout.read()
print ssh_stderr.read()

But I get the following output:

rake aborted!
LoadError: no such file to load -- ruby-debug
/mnt/app-production/releases/20141113171842/config/application.rb:7:in `<top (required)>'
/mnt/app-production/releases/20141113171842/Rakefile:5:in `require'
/mnt/app-production/releases/20141113171842/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)

What is this error? And how can i execute the command successfully?

Thanks

nish
  • 6,952
  • 18
  • 74
  • 128

2 Answers2

0

I think the problem is that you are trying to run multiple commands using exec_command. Check this out: How do you execute multiple commands in a single session in Paramiko? (Python)

Community
  • 1
  • 1
0

i managed to make it work by using the following:

ssh_stdin, ssh_stdout, ssh_stderr = ssh_client.exec_command(" export PATH=/usr/local/rubies/1.9.2-p320/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games ; 
export RUBBER_ENV=production ; 
export RAILS_ENV=production; 
cd /mnt/app-production/current ; bundle exec rake images:load_swatch")
nish
  • 6,952
  • 18
  • 74
  • 128