Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-17-2004, 11:09 AM
|
#1
|
|
Member
Registered: Jul 2004
Posts: 90
Rep:
|
check file permissions in a script
I am working on some scripts that will be run to make sure certain files are set to the right permission within a RHEL2.1AS system. Is there any program that will return a file or directory's permission settings in the format of 766 or similar? I could hack away at an ls -ls output with text editing commands to dig out the permissions on drwxrwxrwx format, but there's gotta be a better way. Any help?
|
|
|
|
09-17-2004, 11:32 AM
|
#2
|
|
Member
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430
Rep:
|
Go for
stat filename
stat -c %a Filename
- For octal values i.e 644 etc
stat -c %A filename
- for human readable values rwx
Cheers
Z
|
|
|
|
09-17-2004, 11:47 AM
|
#3
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
find -printf "%m\t%P\n"
Cheers,
Tink
|
|
|
|
09-20-2004, 09:01 AM
|
#4
|
|
Member
Registered: Jul 2004
Posts: 90
Original Poster
Rep:
|
forgive me if I am showing my "newbieness" here, but I can't get either of those commands to work. the stat command seems like exactly what I need, except that when I run it as instructed, I get an error saying the -c option is invalid. All the other options give me so much output i'd still have to do alot of parsing to get the info I need. Did I mess something up or is there another option?
|
|
|
|
09-20-2004, 10:11 AM
|
#5
|
|
Member
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430
Rep:
|
First tell me what shell are you using ?
And its stat -c [small case not upper case]
Also try
man stat
to get the exact syntax
Cheers
Z
|
|
|
|
09-20-2004, 03:21 PM
|
#6
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
This may be a silly question, but if you only
want to make sure that certain files do have certain
permissions, why do you need to check them
first? :} ... It would be enough to set the script
up to just force them ;)
Cheers,
Tink
|
|
|
|
09-20-2004, 03:35 PM
|
#7
|
|
Member
Registered: Jul 2004
Posts: 90
Original Poster
Rep:
|
i'm using a bash shell. The man page for stat only lists the options as -l, f, v, and t as options, all lowercase. I'm not sure what the c options is suppose to give me, but I just realized what I was doing with the find command and have gotten thatt to work. Problem solved i suppose.
|
|
|
|
09-21-2004, 02:16 PM
|
#8
|
|
Member
Registered: Jul 2004
Posts: 90
Original Poster
Rep:
|
Quote:
Originally posted by Tinkster
This may be a silly question, but if you only
want to make sure that certain files do have certain
permissions, why do you need to check them
first? :} ... It would be enough to set the script
up to just force them 
Cheers,
Tink
|
the script is being written to test security compliance. According to guidelines, certain files, such as /etc/passwd are to be set to a certain mode. Natually, the default is correct on most installs, but i'd like for the script to check anyway just in case somehow something changed it.
|
|
|
|
09-21-2004, 02:40 PM
|
#9
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
In that case (auditing) you probably want to be looking
at tripwire or AIDE, or would that be overkill?
Cheers,
Tink
|
|
|
|
09-22-2004, 12:13 AM
|
#10
|
|
Member
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430
Rep:
|
But tripwire will give you enough data to make you crazy.
Even miniscule changes will be reported and you`ll not get what you exactly need
such as permission of file changed .etc. [ If thats the only thing you are looking forward to do]
Cheers
Z
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:56 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|