Re: Automate rsync w/ authentication

2009-07-13 Thread Bryan
On Jul 10, 12:03 pm, mgi...@motorola.com (Gary Duzan) wrote:
 In article 
 3af970b1-b454-4d56-a33f-889ecfaca...@l28g2000vba.googlegroups.com,

 Bryan  bryanv...@gmail.com wrote:

 rsyncExec = '/usr/bin/ssh'
 source = 'r...@10.0.45.67:/home/bry/jquery.lookup'
 dest = '/home/bry/tmp'
 rshArg = '-e /usr/bin/ssh -i /home/bry/keys/brybackup.key'
 args = [rsyncExec, '-a', '-v', '--dry-run', rshArg, source, dest]

    I think you want -e and the ssh command to be separate args.
 Something like:

 rshArg = '/usr/bin/ssh -i /home/bry/keys/brybackup.key'
 args = [rsyncExec, '-a', '-v', '--dry-run', '-e', rshArg, source, dest]

 or:

 rshArgs = [ '-e', '/usr/bin/ssh -i /home/bry/keys/brybackup.key' ]
 args = [rsyncExec, '-a', '-v', '--dry-run'] +  rshArgs + [ source, dest]

                                         Gary Duzan
                                         Motorola HNM

Separating the argument parts worked.  Strangely though, I don't need
to do that for arguments such as --files-from='/path/to/file'.  Also,
in this example code I had the rsync executable path pointing to the
ssh program, so no wonder I was getting the output of ssh!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automate rsync w/ authentication

2009-07-13 Thread Piet van Oostrum
 Bryan bryanv...@gmail.com (B) wrote:

B On Jul 10, 12:03 pm, mgi...@motorola.com (Gary Duzan) wrote:
 In article 
 3af970b1-b454-4d56-a33f-889ecfaca...@l28g2000vba.googlegroups.com,
 
 Bryan  bryanv...@gmail.com wrote:
 
 rsyncExec = '/usr/bin/ssh'
 source = 'r...@10.0.45.67:/home/bry/jquery.lookup'
 dest = '/home/bry/tmp'
 rshArg = '-e /usr/bin/ssh -i /home/bry/keys/brybackup.key'
 args = [rsyncExec, '-a', '-v', '--dry-run', rshArg, source, dest]
 
    I think you want -e and the ssh command to be separate args.
 Something like:
 
 rshArg = '/usr/bin/ssh -i /home/bry/keys/brybackup.key'
 args = [rsyncExec, '-a', '-v', '--dry-run', '-e', rshArg, source, dest]
 
 or:
 
 rshArgs = [ '-e', '/usr/bin/ssh -i /home/bry/keys/brybackup.key' ]
 args = [rsyncExec, '-a', '-v', '--dry-run'] +  rshArgs + [ source, dest]
 
                                         Gary Duzan
                                         Motorola HNM

B Separating the argument parts worked.  Strangely though, I don't need
B to do that for arguments such as --files-from='/path/to/file'.  Also,
B in this example code I had the rsync executable path pointing to the
B ssh program, so no wonder I was getting the output of ssh!

I should have seen that because I changed it in my own copy!!!

--files-from='/path/to/file *is* one argument, in contrast to 
-e /usr/bin/ssh -i /home/bry/keys/brybackup.key which is two
arguments.

-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automate rsync w/ authentication

2009-07-11 Thread Gary Duzan
In article 3af970b1-b454-4d56-a33f-889ecfaca...@l28g2000vba.googlegroups.com,
Bryan  bryanv...@gmail.com wrote:

rsyncExec = '/usr/bin/ssh'
source = 'r...@10.0.45.67:/home/bry/jquery.lookup'
dest = '/home/bry/tmp'
rshArg = '-e /usr/bin/ssh -i /home/bry/keys/brybackup.key'
args = [rsyncExec, '-a', '-v', '--dry-run', rshArg, source, dest]

   I think you want -e and the ssh command to be separate args.
Something like:

rshArg = '/usr/bin/ssh -i /home/bry/keys/brybackup.key'
args = [rsyncExec, '-a', '-v', '--dry-run', '-e', rshArg, source, dest]

or:

rshArgs = [ '-e', '/usr/bin/ssh -i /home/bry/keys/brybackup.key' ]
args = [rsyncExec, '-a', '-v', '--dry-run'] +  rshArgs + [ source, dest]

Gary Duzan
Motorola HNM


-- 
http://mail.python.org/mailman/listinfo/python-list


Automate rsync w/ authentication

2009-07-10 Thread Bryan
I am trying to automate rsync to backup server A from server B.  I
have set up a private/public key between the two servers so I don't
have to enter a password when using rsync.  Running rsync manually
with the following command works fine:
rsync -av --dry-run -e /usr/bin/ssh -i /home/bry/keys/brybackup.key
r...@10.0.45.67:/home/bry/jquery.lookup /home/bry/tmp

But when I try to do it with python, the subprocess simply returns the
ssh -h output on stderr like I am passing some invalid syntax.  What
is wrong in my translation of rsync's -e command from shell to
pythyon?

#! /usr/bin/python
from subprocess import Popen, PIPE
rsyncExec = '/usr/bin/ssh'
source = 'r...@10.0.45.67:/home/bry/jquery.lookup'
dest = '/home/bry/tmp'
rshArg = '-e /usr/bin/ssh -i /home/bry/keys/brybackup.key'
args = [rsyncExec, '-a', '-v', '--dry-run', rshArg, source, dest]
try:
p = Popen(args, stdout=PIPE, stderr=PIPE)
print 'rsync running with pid %s' % p.pid
out, err = p.communicate()
print 'Errors: %s' % err
print 'Output: %s' % out
except Exception:
print 'Error running rsync'

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automate rsync w/ authentication

2009-07-10 Thread Chris Rebert
On Fri, Jul 10, 2009 at 9:13 AM, Bryanbryanv...@gmail.com wrote:
 I am trying to automate rsync to backup server A from server B.  I
 have set up a private/public key between the two servers so I don't
 have to enter a password when using rsync.  Running rsync manually
 with the following command works fine:
 rsync -av --dry-run -e /usr/bin/ssh -i /home/bry/keys/brybackup.key
 r...@10.0.45.67:/home/bry/jquery.lookup /home/bry/tmp

 But when I try to do it with python, the subprocess simply returns the
 ssh -h output on stderr like I am passing some invalid syntax.  What
 is wrong in my translation of rsync's -e command from shell to
 pythyon?

 #! /usr/bin/python
 from subprocess import Popen, PIPE
 rsyncExec = '/usr/bin/ssh'
 source = 'r...@10.0.45.67:/home/bry/jquery.lookup'
 dest = '/home/bry/tmp'
 rshArg = '-e /usr/bin/ssh -i /home/bry/keys/brybackup.key'
 args = [rsyncExec, '-a', '-v', '--dry-run', rshArg, source, dest]

Like many problems involving the subprocess module, I think you've
tokenized the arguments incorrectly. Try:

rshArg = '/usr/bin/ssh -i /home/bry/keys/brybackup.key'
args = [rsyncExec, '-av', '--dry-run', '-e', rshArg, source, dest]

Note that the -e switch and its operand are separate arguments for the
purposes of POSIX shell tokenization.

Cheers,
Chris
-- 
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automate rsync w/ authentication

2009-07-10 Thread Piet van Oostrum
 Chris Rebert c...@rebertia.com (CR) wrote:

CR On Fri, Jul 10, 2009 at 9:13 AM, Bryanbryanv...@gmail.com wrote:
 I am trying to automate rsync to backup server A from server B.  I
 have set up a private/public key between the two servers so I don't
 have to enter a password when using rsync.  Running rsync manually
 with the following command works fine:
 rsync -av --dry-run -e /usr/bin/ssh -i /home/bry/keys/brybackup.key
 r...@10.0.45.67:/home/bry/jquery.lookup /home/bry/tmp
 
 But when I try to do it with python, the subprocess simply returns the
 ssh -h output on stderr like I am passing some invalid syntax.  What
 is wrong in my translation of rsync's -e command from shell to
 pythyon?
 
 #! /usr/bin/python
 from subprocess import Popen, PIPE
 rsyncExec = '/usr/bin/ssh'
 source = 'r...@10.0.45.67:/home/bry/jquery.lookup'
 dest = '/home/bry/tmp'
 rshArg = '-e /usr/bin/ssh -i /home/bry/keys/brybackup.key'
 args = [rsyncExec, '-a', '-v', '--dry-run', rshArg, source, dest]

CR Like many problems involving the subprocess module, I think you've
CR tokenized the arguments incorrectly. Try:

CR rshArg = '/usr/bin/ssh -i /home/bry/keys/brybackup.key'
CR args = [rsyncExec, '-av', '--dry-run', '-e', rshArg, source, dest]

CR Note that the -e switch and its operand are separate arguments for the
CR purposes of POSIX shell tokenization.

I think you should have only one kind of quotes in rshArg:
rshArg = /usr/bin/ssh -i /home/bry/keys/brybackup.key

I haven't tried it, however, but this is just how Unix works.
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automate rsync w/ authentication

2009-07-10 Thread Chris Rebert
On Fri, Jul 10, 2009 at 12:43 PM, Piet van Oostrump...@cs.uu.nl wrote:
 Chris Rebert c...@rebertia.com (CR) wrote:

CR On Fri, Jul 10, 2009 at 9:13 AM, Bryanbryanv...@gmail.com wrote:
 I am trying to automate rsync to backup server A from server B.  I
 have set up a private/public key between the two servers so I don't
 have to enter a password when using rsync.  Running rsync manually
 with the following command works fine:
 rsync -av --dry-run -e /usr/bin/ssh -i /home/bry/keys/brybackup.key
 r...@10.0.45.67:/home/bry/jquery.lookup /home/bry/tmp

 But when I try to do it with python, the subprocess simply returns the
 ssh -h output on stderr like I am passing some invalid syntax.  What
 is wrong in my translation of rsync's -e command from shell to
 pythyon?

 #! /usr/bin/python
 from subprocess import Popen, PIPE
 rsyncExec = '/usr/bin/ssh'
 source = 'r...@10.0.45.67:/home/bry/jquery.lookup'
 dest = '/home/bry/tmp'
 rshArg = '-e /usr/bin/ssh -i /home/bry/keys/brybackup.key'
 args = [rsyncExec, '-a', '-v', '--dry-run', rshArg, source, dest]

CR Like many problems involving the subprocess module, I think you've
CR tokenized the arguments incorrectly. Try:

CR rshArg = '/usr/bin/ssh -i /home/bry/keys/brybackup.key'
CR args = [rsyncExec, '-av', '--dry-run', '-e', rshArg, source, dest]

CR Note that the -e switch and its operand are separate arguments for the
CR purposes of POSIX shell tokenization.

 I think you should have only one kind of quotes in rshArg:
 rshArg = /usr/bin/ssh -i /home/bry/keys/brybackup.key

 I haven't tried it, however, but this is just how Unix works.

Ah, indeed, I think you're probably right. Just goes to show it's not
always easy to get exactly right.

Cheers,
Chris
-- 
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automate rsync w/ authentication

2009-07-10 Thread Bryan
On Jul 10, 12:43 pm, Piet van Oostrum p...@cs.uu.nl wrote:
  Chris Rebert c...@rebertia.com (CR) wrote:
 CR On Fri, Jul 10, 2009 at 9:13 AM, Bryanbryanv...@gmail.com wrote:
  I am trying to automate rsync to backup server A from server B.  I
  have set up a private/public key between the two servers so I don't
  have to enter a password when using rsync.  Running rsync manually
  with the following command works fine:
  rsync -av --dry-run -e /usr/bin/ssh -i /home/bry/keys/brybackup.key
  r...@10.0.45.67:/home/bry/jquery.lookup /home/bry/tmp

  But when I try to do it with python, the subprocess simply returns the
  ssh -h output on stderr like I am passing some invalid syntax.  What
  is wrong in my translation of rsync's -e command from shell to
  pythyon?

  #! /usr/bin/python
  from subprocess import Popen, PIPE
  rsyncExec = '/usr/bin/ssh'
  source = 'r...@10.0.45.67:/home/bry/jquery.lookup'
  dest = '/home/bry/tmp'
  rshArg = '-e /usr/bin/ssh -i /home/bry/keys/brybackup.key'
  args = [rsyncExec, '-a', '-v', '--dry-run', rshArg, source, dest]
 CR Like many problems involving the subprocess module, I think you've
 CR tokenized the arguments incorrectly. Try:
 CR rshArg = '/usr/bin/ssh -i /home/bry/keys/brybackup.key'
 CR args = [rsyncExec, '-av', '--dry-run', '-e', rshArg, source, dest]
 CR Note that the -e switch and its operand are separate arguments for the
 CR purposes of POSIX shell tokenization.

 I think you should have only one kind of quotes in rshArg:
 rshArg = /usr/bin/ssh -i /home/bry/keys/brybackup.key

 I haven't tried it, however, but this is just how Unix works.
 --
 Piet van Oostrum p...@cs.uu.nl
 URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
 Private email: p...@vanoostrum.org

I tried removing the internal quotes, and splitting '-e' from the
other arguments.  I still get the same ssh -h output however:

rshArg = '/usr/bin/ssh -i /home/bry/keys/brybackup.key'
args = [rsyncExec, '-a', '-v', '--dry-run', '-e', rshArg, source,
dest]
p = Popen(args, stdout=PIPE, stderr=PIPE)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automate rsync w/ authentication

2009-07-10 Thread Piet van Oostrum
 Bryan bryanv...@gmail.com (B) wrote:

B I tried removing the internal quotes, and splitting '-e' from the
B other arguments.  I still get the same ssh -h output however:

B rshArg = '/usr/bin/ssh -i /home/bry/keys/brybackup.key'
B args = [rsyncExec, '-a', '-v', '--dry-run', '-e', rshArg, source,
B dest]
B p = Popen(args, stdout=PIPE, stderr=PIPE)

For me it works. Of course I substituted local server names, file names
etc. I run this on Mac OS X 10.4.11. The server is some Linux system.


#! /usr/bin/env python

from subprocess import Popen, PIPE
rsyncExec = '/usr/local/bin/rsync'

source = 'xxx.cs.uu.nl:/users/piet/yy'
dest = '/Users/piet/TEMP/test.rsync'

rshArg = '/usr/bin/ssh -i /Users/piet/.ssh/id_rsa'

args = [rsyncExec, '-a', '-v', '-e', rshArg, source, dest]

try:
p = Popen(args, stdout=PIPE, stderr=PIPE)
print 'rsync running with pid %s' % p.pid
out, err = p.communicate()
print 'Errors: %s' % err
print 'Output: %s' % out
except Exception:
print 'Error running rsync'


It just copies the file.
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list