Checking if the directory has read and write permission


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Checking if the directory has read and write permission
# 1  
Checking if the directory has read and write permission

Code:
logMsg='Started by '${USER}
   LOG_MESSAGE "${logMsg}"
   resultCode=$?
   if [[ ${resultCode} -ne ${OK} ]]; then
      return ${resultCode}
   fi
   touch ${FILELISTPATH}
   resultCode=$?
   if [[ ${resultCode} -ne ${OK} ]]; then
      logMsg='failed to create file list:'${FILELISTPATH}
      LOG_ERROR "${logMsg}" CUSTOM_PREPROCESS ${FATAL}
   fi

if [[ ! -r $MMREJ ] && [ ! -w $MMREJ ] ||[ ! -r $MMIN ] && [ ! -w $MMIN ] || [ ! -r $MMLOG ] && [ ! -w $MMLOG ]];then       
	return ${FATAL}

# 2  
Hello raka123,

Welcome to UNIX forums, good that you are showing us your effort/code sample; but mentioning 1 liner in title will NOT help people to help you.
So kindly update your post with complete details about your complete ask. Wherever applicable try to post samples of input and expected output too.


Thanks,
R. Singh
# 3  
Assuming that you mean that you want to terminate this code by returning $FATAL if one or more of the files mentioned in your if statement tests are not both readable and writeable, you probably want to change:
Code:
if [[ ! -r $MMREJ ] && [ ! -w $MMREJ ] ||[ ! -r $MMIN ] && [ ! -w $MMIN ] || [ ! -r $MMLOG ] && [ ! -w $MMLOG ]];then       
	return ${FATAL}

to something more like:
Code:
if [ ! -r "$MMREJ" ] || [ ! -w "$MMREJ"  ] || \
   [ ! -r "$MMIN" ] || [ ! -w "$MMIN" ] || \
   [ ! -r "$MMLOG" ] || [ ! -w "$MMLOG" ]
then	return "${FATAL}"
fi

Note, also, that none of the variables this script is using have been defined by anything you have shown us. If they aren't defined before they are used, the chances of any of this working are pretty small.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #360
Difficulty: Medium
The find command first appeared in Version 4 AT&T UNIX.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux sftp — how to add new user to access exist directory with write permission?

I have built a website and I can access and edit the website'files on server via the root user. The current file and directory structures are not changeable. Now I am hiring a webpage designer to help me re-design some pages, I am going to let the designer edit the files directly on the server. So... (5 Replies)
Discussion started by: uwo-g-xw
5 Replies

2. Solaris

Giving read write permission to user for specific directories and sub directories.

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. This is for Solaris. Please help. (1 Reply)
Discussion started by: blinkingdan
1 Replies

3. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

4. Web Development

Apache write permission issues to another user owned directory

Hi I am trying to make a web program which is command line equivalent. i have done the coding in cgi program in perl and html for basic forms to take inputs. when i ran the program from web application i see permission denied messages. after analyzing i found apache is running as wwwrun which... (2 Replies)
Discussion started by: rakeshkumar
2 Replies

5. Ubuntu

how to make others have read/write permission when the aotu mounted usb flash disk pluge in ?

hi all: as we know , when usb flash disk plug in and aotu mounted , the default permission of the usb flash disk is 700. that means others have no permission . the question: how to make others have read/write permission when the aotu mounted usb flash disk pluge in ? thanks !! (0 Replies)
Discussion started by: arnold.king
0 Replies

6. Shell Programming and Scripting

perl script to check read/write/execute permission for 'others'

I want to check access rights permissions not for 'user', not for 'group', but for 'others'. I want to do it by system command in which i want to use 'ls -l' and 'awk' command. I have written the following program : #!/usr/bin/local/perl #include <stdlib.h> system ("ls -l | awk... (1 Reply)
Discussion started by: shubhamsachdeva
1 Replies

7. Shell Programming and Scripting

write permission to a perticular user to a directory

Hi, The requirement is like, the program needs 2 argument one is user_id and second one is directory path. My script will check if that user_id has write access to the directory path. The directory path may be in any file system like AFS or NFS. Can any one please suggest some points to... (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

8. Shell Programming and Scripting

Find all files with group read OR group write OR user write permission

I need to find all the files that have group Read or Write permission or files that have user write permission. This is what I have so far: find . -exec ls -l {} \; | awk '/-...rw..w./ {print $1 " " $3 " " $4 " " $9}' It shows me all files where group read = true, group write = true... (5 Replies)
Discussion started by: shunter63
5 Replies

9. Programming

How to read and write directory or file contents in c++ ?

Dear Friends, I m beginner unix programmer. I want to know, how to read and write directory or file contents in c++ ? (3 Replies)
Discussion started by: namrata5
3 Replies

Featured Tech Videos