![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| script to gather weblogic jvm heap size stats | galenw | Shell Programming and Scripting | 2 | 02-07-2008 01:34 PM |
| How to perform addition of two numbers in shell scripting in Solaris-10 | krevathi1912 | SUN Solaris | 9 | 11-29-2007 09:36 AM |
| Unix shell scripting to find latest file having timestamp embedded... | kaushik25 | AIX | 2 | 08-06-2007 10:42 PM |
| Scripting file permission problems... | Heron | Shell Programming and Scripting | 3 | 03-24-2005 10:34 AM |
| unix to win2k permission | dozy | Windows & DOS: Issues & Discussions | 0 | 04-21-2004 04:00 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Gather File permission during scripting on unix as numbers.
Hi,
I have a script with following file permission on box. -rwxr-xr-x 1 root system 15347 Aug 14 15:08 b_reboot.ksh Without calculating or watching at -rwxr-xr-x (permission's) of this above mentioned file. I would like to get the file permission assigned to a file. Basically looking for after issuing some commands <file name>, I should get the permission of provided file in a variable as 755. (as a number, either 755/644..or what ever it is.) Example, $some_command <file_name> $permission=$? And the output which I looking forward is like this. $print ${permission} 755 Do we have any command which can substitute "some_command" like this on Unix.? Note: ------ I don't like to go for the manipulation using the ls -l |grep <filename> |awk '{print $1}' Looking for any thing which can be easily done to retrieve permission of file in numbers. |
|
||||
|
from what I read, ajilesh is wanting to see what the permissions are in a non-volatile way. I don't know how you do this in csh, but in ksh you can do this:
if [[ -x /usr/lib/sendmail ]] this is true if the user doing the condition, can execute /usr/lib/sendmail if [[ -r /usr/lib/sendmail ]] this is true if the user doing the condition, can read /usr/lib/sendmail if [[ -w /usr/lib/sendmail ]] this is true if the user doing the condition, can write /usr/lib/sendmail but this only checks the permissions of the user performing the, in this case, if/then/else has those permissions. I do not know of any way to convert rwxrw-rw- to the octal 755 to then confirm you have the correct permissions on said file or directory. I have run into this same problem in my own scripting because the file I was checking on needed to be 766 and I was trying to track down when the permissions got changed so I could figure out what was changing the permissions, the only option I found was to ls -l <file> then pipe that into a grep on "rwxrw\-rw\-" to confirm (yes, \- is necessary to ensure it doesn't try to treat -rw as an option some how) it had the correct permissions. while using chmod is a good suggestion, chmod sets the permissions without regard to the previous state. |
|
||||
|
If you have Perl, you can use that as a workaround.
Code:
perl -e 'for (@ARGV) { printf "%04o %s", (stat)[2] & 07777, $_ }' files ...
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| unix commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|