LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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



Reply
 
Search this Thread
Old 09-17-2004, 12:09 PM   #1
cambie
Member
 
Registered: Jul 2004
Posts: 90

Rep: Reputation: 15
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?
 
Old 09-17-2004, 12:32 PM   #2
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
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
 
Old 09-17-2004, 12:47 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
find -printf "%m\t%P\n"


Cheers,
Tink
 
Old 09-20-2004, 10:01 AM   #4
cambie
Member
 
Registered: Jul 2004
Posts: 90

Original Poster
Rep: Reputation: 15
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?
 
Old 09-20-2004, 11:11 AM   #5
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
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
 
Old 09-20-2004, 04:21 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 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
 
Old 09-20-2004, 04:35 PM   #7
cambie
Member
 
Registered: Jul 2004
Posts: 90

Original Poster
Rep: Reputation: 15
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.
 
Old 09-21-2004, 03:16 PM   #8
cambie
Member
 
Registered: Jul 2004
Posts: 90

Original Poster
Rep: Reputation: 15
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.
 
Old 09-21-2004, 03:40 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
In that case (auditing) you probably want to be looking
at tripwire or AIDE, or would that be overkill?


Cheers,
Tink
 
Old 09-22-2004, 01:13 AM   #10
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a file inherit script permissions antony.booth Linux - Security 4 03-11-2005 06:04 AM
Unable to run /usr/sbin/pppd. --> Check permissions [solved] flosch Linux - Networking 0 05-05-2004 10:08 AM
Script to check for contents in a file darin3200 Programming 7 04-25-2004 06:26 PM
How can I check wether a file is empty in Linux by using shell script programming ??? Bassam Linux - General 2 02-26-2004 02:01 AM
Need script to check file size. _TK_ Linux - General 1 08-06-2001 09:30 AM


All times are GMT -5. The time now is 09:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration