0

I created a Python script that requires sudo permissions to run (doing ICMP requests). This script creates a small directory and a couple .csv files, as well as a log.txt file. At first, after running the program, I was able to delete the artifacts after running to test directory and file creation.

Now, all of a sudden, OS X Finder is asking me for permissions to delete the directory and log file. I performed a chmod 775 * on the directory I have my module in and deleted the folder and file as necessary. However, after running the script again, it requires me to fulfill permissions yet again. Another chmod, I can delete the files and folders. However, every time I run the program I run into the same issue.

Any suggestions on how I can fix this permanently?

7
  • Put the chmod command into the python script?
    – jimtut
    Commented Jul 9, 2014 at 16:38
  • I could, but that sounds risky. Why is this happening in the first place?
    – Blairg23
    Commented Jul 9, 2014 at 20:24
  • A brief sudo mkdir foobar test gives me the same results, in the Finder. I can actually delete it from the Terminal without being prompted, but the Finder prompts me. The Terminal could be because I just did the sudo (but that's not my understanding of sudo privileges) or it could be because I'm in the same group (staff) as root.
    – jimtut
    Commented Jul 10, 2014 at 2:46
  • I think that's probably the problem. My python code has to be run with sudo privileges because it's running ICMP commands and then it creates those files and folders, which is probably being done under those sudo privvies. I wonder if there's a way to "unsudo" in my script after I do the ICMP command.
    – Blairg23
    Commented Jul 11, 2014 at 5:31
  • Yes, the new folder/files are owned by root, not "you". Since you're running under sudo, though, you could use a command like chown to make you the own of the folder/files again, then you could delete in the Finder without getting a prompt. So, I think adding a chown or a chmod in the Python script should do the trick!
    – jimtut
    Commented Jul 11, 2014 at 12:36

1 Answer 1

0

Based on the comments above between the op and me, the root cause of the permission problem is that the folder/files created in the Python script are owned by root, not the op's user account. Anything created while running sudo will be owned by root.

Workarounds for this are to include a chmod or chown command in the script, giving the op's user account permission to delete the file/folder. I recommend chown, as it's possible that the Finder (in Mavericks) is detecting that root is the owner and prompting the user. This happens to me even when my account has full permissions (through the group permissions). Finder could be putting an extra level of protection on root-owned files. Using chown in the script should set everything right for Terminal and Finder!

1
  • Dang, it won't let me vote it up until I have 15 rep tho. However, I was still able to accept as best answer. Perhaps you can vote up my question so I have more reputation and I'll pass it along :)
    – Blairg23
    Commented Jul 16, 2014 at 19:35

You must log in to answer this question.

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