To check the file permissions using python scripting


 
Thread Tools Search this Thread
Top Forums Programming To check the file permissions using python scripting
# 1  
Old 04-29-2013
To check the file permissions using python scripting

Hi,

For a particular set of files, am trying to check if they are writable. i.e., checking whether they are having permissions greater than 755.
Am able to check this using the statement:
"if (os.path.isfile(FILE_PATH) and (os.stat(FILE_PATH).st_mode & 0777) == 0777):"

But the problem here is am exactly not sure, which all are the write permissions on a file.

or, is there any other way to check if file is having permissions greater than 755,

Any help in this regard is useful.
Thanks,
Arjun
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

What's the best way to check file permissions before moving files if needed?

Hello, I would like to know if it's a good practice to check the file permissions of the contents of a directory before moving them. For example: mv -- "$directory"/* "$directory"/.* "$directory"/..?* "$destination"The variables $directory and $destination contain the path to an existing... (6 Replies)
Discussion started by: Cacializ
6 Replies

2. UNIX for Dummies Questions & Answers

Is there a way to check when the permissions for the file got changed in AIX

Is there a way to check when the permissions for the file got changed in AIX IS there some file which logs all these details? Best regards, Vishal (4 Replies)
Discussion started by: Vishal_dba
4 Replies

3. Shell Programming and Scripting

To check the file permissions using python scripting

Hi, For a particular set of files, am trying to check if they are writable. i.e., checking whether they are having permissions greater than 755. Am able to check this using the statement: "if (os.path.isfile(FILE_PATH) and (os.stat(FILE_PATH).st_mode & 0777) == 0777):" But the problem... (1 Reply)
Discussion started by: arjun_arippa
1 Replies

4. Homework & Coursework Questions

Check the permissions user

i have some question for example: suppose we have the Public folder as follows: https://www.unix.com/attachments/shell-programming-scripting/2759d1334070669-check-permissions-linux-user-capture.png If user enter: -Kenshin or /home/kenshin/Public output: abc: kenshin: rw my shell:... (1 Reply)
Discussion started by: kingkner
1 Replies

5. Shell Programming and Scripting

Scripting to check the size of file and it's existance.

Hi, I am totaly new to create a script . Please help. I have file name retrived from SAP table into a internal table . Like :- /home/td_8d02_int_data_IPCL/ILLUSTRATIONS/CGM/l_pc_112138_01_0_01_00.cgm /home/td_8d02_int_data_IPC-L/ILLUSTRATIONS/CMP/l_pc_112138_01_0_01_00.cmp Objective... (1 Reply)
Discussion started by: amitkumar.b2
1 Replies

6. Shell Programming and Scripting

How to check file permissions from a script.

hello, I have to write a script to run the other script inside it.So iam planning to write like this? first check the perimissions of the file. Alogorthim ---------- if(!filepermissions == execute) then echo" Permissions denined" else execute the script. file name is : load_mf.sh... (1 Reply)
Discussion started by: rajkumar_g
1 Replies

7. Shell Programming and Scripting

Crontab Permissions Issue with Python

I have a cron on a Linux server that isn't executing properly. CRON (with specific info replaced): MAILTO=emailaddress@server.com */2 * * * * python /data/site/cron.py OUTPUT: python: can't open file '/data/site/cron.py ': No such file or directoryAdditional info - The python path is... (3 Replies)
Discussion started by: theHire
3 Replies

8. Shell Programming and Scripting

Using grep - check the permissions of the file searched

What I need to do is: I need to use the grep command to search for pattern in directory and sub-directories. And also I need to show the permission of file been seached by the grep command. Could any one please suggest me? ----------------- $> cat file1.txt A -----------------... (8 Replies)
Discussion started by: Johny001
8 Replies

9. Solaris

How to check the file existence using shell scripting in Solaris-10

Hi, I have a script which will check the fiel existence, the lines are as below if !(test -d ./data) then mkdir data fi In the first line error occurs as below generatelicense.sh: syntax error at line 2: `!' unexpected Where as this script works fine in linux OS. How to solve... (2 Replies)
Discussion started by: krevathi1912
2 Replies

10. Shell Programming and Scripting

file permissions using shell scripting

Hi I am trying to use shell script to display file permissions, and I can do it fine for the current user logged in, but now I want to view all file permissions for the Owner of the file, Group users and everyone, so it will look something like this: -----------------READ WRITE EXECUTE OWNER... (11 Replies)
Discussion started by: barbus
11 Replies
Login or Register to Ask a Question
ACCESS(2)						     Linux Programmer's Manual							 ACCESS(2)

NAME
access - check user's permissions for a file SYNOPSIS
#include <unistd.h> int access(const char *pathname, int mode); DESCRIPTION
access checks whether the process would be allowed to read, write or test for existence of the file (or other file system object) whose name is pathname. If pathname is a symbolic link permissions of the file referred to by this symbolic link are tested. mode is a mask consisting of one or more of R_OK, W_OK, X_OK and F_OK. R_OK, W_OK and X_OK request checking whether the file exists and has read, write and execute permissions, respectively. F_OK just requests checking for the existence of the file. The tests depend on the permissions of the directories occurring in the path to the file, as given in pathname, and on the permissions of directories and files referred to by symbolic links encountered on the way. The check is done with the process's real uid and gid, rather than with the effective ids as is done when actually attempting an operation. This is to allow set-UID programs to easily determine the invoking user's authority. Only access bits are checked, not the file type or contents. Therefore, if a directory is found to be "writable," it probably means that files can be created in the directory, and not that the directory can be written as a file. Similarly, a DOS file may be found to be "exe- cutable," but the execve(2) call will still fail. If the process has appropriate privileges, an implementation may indicate success for X_OK even if none of the execute file permission bits are set. RETURN VALUE
On success (all requested permissions granted), zero is returned. On error (at least one bit in mode asked for a permission that is denied, or some other error occurred), -1 is returned, and errno is set appropriately. ERRORS
access shall fail if: EACCES The requested access would be denied to the file or search permission is denied to one of the directories in pathname. ELOOP Too many symbolic links were encountered in resolving pathname. ENAMETOOLONG pathname is too long. ENOENT A directory component in pathname would have been accessible but does not exist or was a dangling symbolic link. ENOTDIR A component used as a directory in pathname is not, in fact, a directory. EROFS Write permission was requested for a file on a read-only filesystem. access may fail if: EFAULT pathname points outside your accessible address space. EINVAL mode was incorrectly specified. EIO An I/O error occurred. ENOMEM Insufficient kernel memory was available. ETXTBSY Write access was requested to an executable which is being executed. RESTRICTIONS
access returns an error if any of the access types in the requested call fails, even if other types might be successful. access may not work correctly on NFS file systems with UID mapping enabled, because UID mapping is done on the server and hidden from the client, which checks permissions. Using access to check if a user is authorized to e.g. open a file before actually doing so using open(2) creates a security hole, because the user might exploit the short time interval between checking and opening the file to manipulate it. CONFORMING TO
SVID, AT&T, POSIX, X/OPEN, BSD 4.3 SEE ALSO
stat(2), open(2), chmod(2), chown(2), setuid(2), setgid(2) Linux 2002-04-23 ACCESS(2)