I have a script that, when run, creates a directory inside /home/test/
and then writes some files in it. When I run this script, it works fine. However, when I call it from a perl script with
$ret = `/home/..../testscript.py`
it doesn't have permissions so it can't create the folder, or can't write inside it after it is created. It looks like when Python does open("/home/test/abcde/file1.txt", "w")
, that file has permissions -rw-r--r--
What can I do to get around this? Is there a way to set /home/test to recursively make all subdirectories have global write-access? Or a better solution maybe?
Easiest way to set permissions to 777 is to connect to Your server through FTP Application like FileZilla, right click on folder, module_installation, and click Change Permissions - then write 777 or check all permissions. Save this answer.
To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or “a” (for all). chmod ugo+rwx foldername to give read, write, and execute to everyone. chmod a=r foldername to give only read permission for everyone.
Use the chmod command to change the permissions for all files, directories, and subdirectories. Note – The permission 755 is good to set for directories but not on files. This set the execute bit on files which is not recommended for any production environments excluded some specific cases.
Put:
os.umask(0000)
in the Python script before it creates the directory. If you can't change the Python script, put:
umask(0000)
in the Perl script before it calls the Python script.
When a new file or directory is created, the permissions are determined by taking the permissions specified in the call to creat()
or mkdir()
, and then masking off the bits that are specified in the umask
.
Typically, applications specify 0666
or 0777
permissions when they call the function (depending on whether they're creating something that should be executable or not). A common value for umask
is 022
, which turns off group and world write permissions. If you don't want them turned off, use the above umask
value to keep the permissions specified in the call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With