Operating System - HP-UX
1828670 Members
2238 Online
109984 Solutions
New Discussion

need help with a script to check if /etc/mail/aliases file has 600 permission

 
SOLVED
Go to solution
chicuks
Advisor

need help with a script to check if /etc/mail/aliases file has 600 permission

hi

i need help with a script to check if

/etc/mail/aliases file has 600 permission

if it has 600 permission then it will echo OK

Or else if its not there then it will echo NOK
8 REPLIES 8
Pete Randall
Outstanding Contributor

Re: need help with a script to check if /etc/mail/aliases file has 600 permission

You're kidding right?

Why not just look at at it? "ll /etc/mail/aliases"

If you really must do it in a script then use the ll command and parse the output. Or use the find command with the -name and -perm options.


Pete

Pete
chicuks
Advisor

Re: need help with a script to check if /etc/mail/aliases file has 600 permission

hi pete

am not kidding!!

i know u just have to do ll... but u cn use it in the script if possible . this is to keep a track .. then later may be cron be implemented to get the periodic output of the changes..
Pete Randall
Outstanding Contributor

Re: need help with a script to check if /etc/mail/aliases file has 600 permission

You want to keep track? OK.

ll /etc/mail/aliases >> /var/tmp/aliases_perm.log


Pete

Pete
chicuks
Advisor

Re: need help with a script to check if /etc/mail/aliases file has 600 permission

thanks Pete

but this is not what i want
ur solution is directing to logs..

but i want to keep a track in real time...

my aim is to create a script to check
if /etc/mail/aliases has the file permission has 600 permission(The aliases file is owned by root programs executed & aliases file entry should be owned by root & resides in a directory that is owned by root)

if its any thing other than 600 then it will give an output of Error . that will be done by a GUI tool which will be triggered by cron messeges.

but before that we need a script in place to this check. when the script is run it will give an error which in return give an error in the tool thruogh cron


i hope you understand.. btw thanx fr ur effort

TTr
Honored Contributor
Solution

Re: need help with a script to check if /etc/mail/aliases file has 600 permission

I assume this is part of a security check?

Do you know that sendmail (newaliases) will refuse to process the /etc/mail/aliases file if it does NOT have the right ownership and permission. (although the file can still be readable and the directory can be traversed).

What are you going to do if the directory itself /etc/mail changes permissions?

What about /etc/mail/aliases.db? This file is worth more than /etc/mail/aliases

Anyway this ought to do it. Even if the file does not exist it will echo NOK.
/usr/bin/sh
if [ -f /etc/mail/aliases ]
then
aliasesmode=`ll /etc/mail/aliases | cut -c 1-10`
[ "$aliasesmode" = "-rw-------" ] && echo OK || echo NOK
else
echo NOK #file does not exist
fi
James R. Ferguson
Acclaimed Contributor

Re: need help with a script to check if /etc/mail/aliases file has 600 permission

Hi:

I'm sorry to say that I agree with Pete.

Your questions have great similarity insofar as you want to perform simple queries of files or command output and print "OK" or "NOT_OK". I gave you an example yesterday in your thread:

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1375254

You should re-read my comments there and learn to do a bit of very basic scripting.

Regards!

...JRF...

chicuks
Advisor

Re: need help with a script to check if /etc/mail/aliases file has 600 permission

Thanx Ttr

yes you are rite it is part of security check

i Totally agrre to your ponts u mentioned for aliases file

the script is still fine wit me
chicuks
Advisor

Re: need help with a script to check if /etc/mail/aliases file has 600 permission

thnx