Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I plan to move file from one system to another system. For this, I am using rsync command in linux terminal. It works fine. But I need to implement this command to python. I am very new in python, so I don't know the way of defining the rsync command. So please tell the steps to define it. This is my rsync command:

rsync -avrz /opt/data/filename root@ip:/opt/data/file

I need to implement this command in a python script.

share|improve this question

closed as off topic by jokerdino, izx, con-f-use, John S Gruber, SirCharlo Aug 22 '12 at 13:40

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.

Is this Ubuntu-specific? If not, it should be migrated to StackOverflow. –  hexafraction Jul 6 '12 at 13:36
General programming questions that are not specifically related to Ubuntu are off-topic here. You might want to try our friends in Stack Overflow for assistance. –  jokerdino Jul 6 '12 at 13:44
This seems like a programming question as applied to a system administration task. For that reason, I'd suggest that it's on-topic here (and a better fit for our site than for Stack Overflow). I do not think we should close this question. –  Eliah Kagan Jul 6 '12 at 13:49
Very similar to How to use tee (or generally a system) command in python? –  con-f-use Aug 20 '12 at 11:14

2 Answers 2

import os
os.system("rsync -avrz /opt/data/filename root@ip:/opt/data/file")

Did you try that?
os.system basically allows you to run bash commands.

share|improve this answer
Please look at the subprocess module instead, where shell support is disabled by default. –  Gringo Suave Dec 7 '14 at 21:59

Note: Please take a moment to look at the answers to your previous questions and accept/upvote as appropriate. Your 0% accept rate here and on StackOverflow may be strongly discouraging potential "answerers" from helping you out, since by not upvoting/accepting, you appear to show no regard for their efforts.

As the answer to your previous similar question suggests, rsync will work just fine as a shell command from within Python if you use SSH keys to authenticate instead of a password. If you need further help with how to set up SSH key-based authentication, please edit your question.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.