From: Chris Brauchli on
Hi,

I am writing a script that, at one point, copies a file from directory
A to directory B. Directory B can only be written to by root, but the
script is always called with sudo, so this shouldn't be an issue, but
it is. I have tried using shutil.copy() and calling "sudo cp " with
os.popen to no avail. I cannot get the script to copy a file to
directory B. The strange thing is if I run the python interpreter (as
sudo) and type in shutil.copy it works. It also works if I try to copy
the file to a less protected directory. It only happens when I try to
copy a file to directory B from a python script.

Any ideas why this is happening? If more information is needed or
something isn't clear let me know. Thanks for helping.

Chris
From: Albert Hopkins on
On Tue, 2010-08-03 at 21:01 -0700, Chris Brauchli wrote:
> Hi,
>
> I am writing a script that, at one point, copies a file from directory
> A to directory B. Directory B can only be written to by root, but the
> script is always called with sudo, so this shouldn't be an issue, but
> it is. I have tried using shutil.copy() and calling "sudo cp " with
> os.popen to no avail. I cannot get the script to copy a file to
> directory B. The strange thing is if I run the python interpreter (as
> sudo) and type in shutil.copy it works. It also works if I try to copy
> the file to a less protected directory. It only happens when I try to
> copy a file to directory B from a python script.
>
> Any ideas why this is happening? If more information is needed or
> something isn't clear let me know. Thanks for helping.
>
> Chris

Code?

Traceback?

From: News123 on
On 08/04/2010 06:01 AM, Chris Brauchli wrote:
> Hi,
>
> I am writing a script that, at one point, copies a file from directory
> A to directory B. Directory B can only be written to by root, but the
> script is always called with sudo, so this shouldn't be an issue, but
> it is. I have tried using shutil.copy() and calling "sudo cp " with
> os.popen to no avail. I cannot get the script to copy a file to
> directory B. The strange thing is if I run the python interpreter (as
> sudo) and type in shutil.copy it works. It also works if I try to copy
> the file to a less protected directory. It only happens when I try to
> copy a file to directory B from a python script.
>
> Any ideas why this is happening? If more information is needed or
> something isn't clear let me know. Thanks for helping.
>

a fiew suggestions suggestions:


1,) open a terminal window with sudo -s and make ALL of the following
tests from this window.

2.) tell use the exact permissions of your destination directory
ls -ld DESTINATION_DIRECTORY

3.) verify, whether the file you want to copy exists already in the
destination directory
ls -l DESTINATION_DIRECTORY/DSTNTN_FILE_NAME


3.) try following python

import os
print os.getcwd()
import shutil
shutil("YOUR_SOURCE_FILE_NAME","DESTINATION_DIRECTORY/DSTNTN_FILE_NAME")


4.) try the same from a shell window
cp YOUR_SOURCE_FILE_NAME DESTINATION_DIRECTORY/DSTNTN_FILE_NAME


From: Steven D'Aprano on
On Tue, 03 Aug 2010 21:01:38 -0700, Chris Brauchli wrote:

> Hi,
>
> I am writing a script that, at one point, copies a file from directory A
> to directory B. Directory B can only be written to by root, but the
> script is always called with sudo, so this shouldn't be an issue, but it
> is. I have tried using shutil.copy() and calling "sudo cp " with
> os.popen to no avail. I cannot get the script to copy a file to
> directory B.
[...]
> Any ideas why this is happening? If more information is needed or
> something isn't clear let me know. Thanks for helping.

Without seeing the traceback and the actual line of code that fails, and
preferably the full set of permissions on the directory, we'd be
guessing. Now, I love to play "debug the program by making wild guesses"
with other people's code, but you might not like my suggestions :)



--
Steven
From: Lawrence D'Oliveiro on
In message <4c5a6d00$0$29614$426a34cc(a)news.free.fr>, News123 wrote:

> The original question lacks necessary information

That seems to be very common in this newsgroup.