File permisson doesn't work | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

File permisson doesn't work

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-07-2013
Pawan Kumar Pawan Kumar is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 11 March 2013, 1:13 AM EDT
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
File permisson doesn't work

Hi,

I used below script to check the file permission but it doesnt work.

Code:
[root@sai4db1 tmp]# ls -ltr
total 52
-rwx------ 1 root root 1563 Mar  6 14:12 ks-script-t-WIE3
---x--x--x 1 root root  599 Mar  6 14:14 ks-script-t-WIE3.log
-rwx------ 1 root root  553 Mar  6 14:14 ks-script-P4gFC6
drwxrwxr-- 2 root root 4096 Mar  6 14:14 SAI-RHEL-SEC-patch
-rw-r--r-- 1 root root 1292 Mar  6 14:15 ks-script-P4gFC6.log
drwxr-xr-x 2 root root 4096 Mar  6 18:30 sai
-rwxr-xr-x 1 root root  147 Mar  7 13:56 test.sh
[root@sai4db1 tmp]# cat test.sh
#!/bin/bash

file="ks-script-t-WIE3.log"

if [ -r $file ]
then
echo "file has read permission"
else
echo "files doesnt have execute permission"
fi
[root@sai4db1 tmp]# ./test.sh
file has read permission
[root@sai4db1 tmp]#

Any idea??

Last edited by Franklin52; 03-07-2013 at 05:59 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #2  
Old 03-07-2013
busyboy busyboy is offline
Registered User
 
Join Date: Jan 2010
Last Activity: 19 March 2014, 3:51 AM EDT
Posts: 191
Thanks: 2
Thanked 9 Times in 9 Posts

Code:
if test -r astropubkey.asc ; then echo "file has r perms"; else echo "file is no r perms"; fi

Sponsored Links
    #3  
Old 03-07-2013
Pawan Kumar Pawan Kumar is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 11 March 2013, 1:13 AM EDT
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Still same issue...Its strange really...


Code:
[root@sai4db1 tmp]# ll
total 52
-rwx------ 1 root root  553 Mar  6 14:14 ks-script-P4gFC6
-rw-r--r-- 1 root root 1292 Mar  6 14:15 ks-script-P4gFC6.log
-rwx------ 1 root root 1563 Mar  6 14:12 ks-script-t-WIE3
---x--x--x 1 root root  599 Mar  6 14:14 ks-script-t-WIE3.log
drwxr-xr-x 2 root root 4096 Mar  6 18:30 sai
drwxrwxr-- 2 root root 4096 Mar  6 14:14 SAI-RHEL-SEC-patch
-rwxr-xr-x 1 root root  148 Mar  7 14:30 test.sh
[root@sai4db1 tmp]# vim test.sh
[root@sai4db1 tmp]# cat test.sh
#!/bin/bash

file="ks-script-t-WIE3.log"

if test -r $file
then
echo "file has read permission"
else
echo "files doesnt have execute permission"
fi
[root@sai4db1 tmp]#


Last edited by Franklin52; 03-07-2013 at 06:00 AM.. Reason: Please use code tags for data and code samples
    #4  
Old 03-07-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 30 August 2014, 2:52 PM EDT
Location: Aachen, Germany
Posts: 4,142
Thanks: 67
Thanked 988 Times in 936 Posts
As I can infer from your prompt you are running that script as root. root may read everything. Try running as a normal user.
Sponsored Links
    #5  
Old 03-07-2013
Pawan Kumar Pawan Kumar is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 11 March 2013, 1:13 AM EDT
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
thanks for reply..
But using root user, it is working for +x checks but not for +r and +w. Any idea why?
Sponsored Links
    #6  
Old 03-07-2013
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 26 June 2014, 10:29 AM EDT
Location: France
Posts: 2,929
Thanks: 80
Thanked 624 Times in 596 Posts
Your line :

Code:
echo "files doesnt have execute permission"

should be replaced with :

Code:
echo "files doesnt have READ permission"

since you are testing against the "-r" option.

If you want to test against the execute permission, in your if test statement, you should use the "-x" option instead.

Last edited by ctsgnb; 03-07-2013 at 05:16 AM..
Sponsored Links
    #7  
Old 03-07-2013
sangfroid sangfroid is offline
Registered User
 
Join Date: May 2007
Last Activity: 25 March 2013, 2:00 PM EDT
Posts: 15
Thanks: 0
Thanked 2 Times in 1 Post
you are running as a root user, try changing ownership of the file to some other user and then test..

also, you are thinking for +x it is working correctly, but in fact check your code as ctsgnb mentioned.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Why doesn't this work? scribling UNIX for Dummies Questions & Answers 4 01-12-2013 09:28 AM
directory structure & file permisson comparison oraclermanpt Shell Programming and Scripting 1 02-14-2012 11:44 PM
What to do when mtime doesn't work? bbbngowc Shell Programming and Scripting 19 03-17-2009 10:15 AM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 09:52 PM
Why doesn't this work? jpeery Shell Programming and Scripting 2 05-14-2004 07:19 PM



All times are GMT -4. The time now is 04:15 PM.