9

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.

4
  • 4
    Is this Ubuntu-specific? If not, it should be migrated to StackOverflow.
    – nanofarad
    Jul 6, 2012 at 13:36
  • 1
    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, 2012 at 13:44
  • 1
    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. Jul 6, 2012 at 13:49
  • 1
    Very similar to How to use tee (or generally a system) command in python?
    – con-f-use
    Aug 20, 2012 at 11:14

2 Answers 2

14
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.

1
  • 8
    Please look at the subprocess module instead, where shell support is disabled by default. Dec 7, 2014 at 21:59
4

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.

Not the answer you're looking for? Browse other questions tagged .