|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
Code:
if test -r astropubkey.asc ; then echo "file has r perms"; else echo "file is no r perms"; fi |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|