1

I wanted to compress a folder on a remote namchine.For that i am using paramiko. But i don't know how to do that using paramiko. Any suggestions??

This is my code:

dpath = '/var/mysql/5.1/mysql.zip' 
port = 22 
host = '10.88.36.7' 
transport = paramiko.Transport((host, port)) 
transport.connect(username=suser, password=spass) 
channel = transport.open_channel(kind="session") 
channel.exec_command('zip -r /var/db/mysql /var/db/mysql') 
transport.close()

whats wrong in this??

I159
31.4k32 gold badges102 silver badges137 bronze badges
asked Oct 13, 2010 at 13:52
2
  • What do you have so far, and how doesn't it work? Commented Oct 13, 2010 at 13:56
  • If you are doing something more elaborate than just this one command, it'd be worthwhile to look into using Fabric <docs.fabfile.org>. It's built on top of paramiko and hides much of this boilerplate code. Commented Oct 13, 2010 at 18:25

1 Answer 1

3

After

channel.exec_command(...)

You have to wait the termination of the command with:

while not channel.exit_status_ready()
 ... wait ... ( you can read the output with channel.recv, or sleep a bit)

Furthermore, you're zip command is weird... don't you want to say

zip -r /var/db/mysql.zip /var/db/mysql
answered Oct 13, 2010 at 14:19
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.