Help with shell script to check the condition.

:slight_smile:
Hi,

I want to script for this scenerio,

OSR Settings

Scenario : We are looking to find all the *.a files from the following locations in the filesystem of a server.

OSR Directories

/etc
/bin
/usr/bin
/usr/sbin
/var/adm

These *.a files should have the permissions on 'Other' as r-x or more stringent.
The script should display only those *.a files which have full permissions (rwx) on their 'Other'.

Also , the *.a files must be owned , only by one of the following userids and groupids:

System UserIds

root ,daemon,bin,sys,adm,uucp,nuucp,lpd,imnadm,ipsec,ldap,lp,snapp,invscout

System GroupIds

system,security,bin,sys,adm,uucp,mail,printq,cron,audit,shutdown,ecs,imnadm,ipsec,ldap,lp,haemrm,snapp,hacmp

The script should display all *.a files that are not owned by any one of the above listed system userids and groupids

Could you please help me anyone?

Thanks in advance...

Regards,
Shakthi

Moving this to the shell scripting area.

this might help you

ls -l *.a|awk '{k=0;for(i=6;i<=8;i++)k+=((substr($1,i+2,1)~/[rwxs]/)*2^(8-i));if(k==7){printf(" %0o ",k);print $9;}}'

Which one is it? Display those owned by the listed UIDs/GIDs or omit those?

Thank you for ur help. Is it also taking care of the *.a files to be owned by system user ids and group ids.?!!

omit those..

it won't check for UID/GID which ever folder you run it it just check for group permission if it's 7(RWX) it will display the filename

ok, Is it possible to check UID and GID also ..(which i have marked) ?

any idea?

yes ofcourse
this will check for UID=root and GID=system

ls -l *.a|awk '{k=0;for(i=6;i<=8;i++)k+=((substr($1,i+2,1)~/[rwxs]/)*2^(8-i));if(k==7 && $3=="root" && $4=="system"){printf(" %0o ",k);print $9;}'

modify as you want:)

$ find /etc /bin /usr/bin /usr/sbin /var/adm \
-name '*.a' \
'!' '(' -user root -o -user daemon -o -user bin -o -user sys ')' \
'!' '(' system -o -group security -o -group bin -o -group sys ')' \
-ls | awk '$3~/[r-]-[x-]$/{print $11}'

Add additional users/groups as needed

Thank your help. but the problem with this script is .. For eg : If there is no *.a file found ,with Owner as System , it terminates the execution there itself and would not excute further. It shows an error message like " System user not found " ..

Please advise

find /etc /bin /usr/bin /usr/sbin /var/adm \ -name '*.a' \ '!' '(' -user root -o -user daemon -o -user bin -o -user sys -o -user adm -o -user uucp -o -user nuucp -o -user lpd -o -user imnadm -o -user ipsec -o -user ldap -o -user lp -o -user snapp -o -user invscout ')' \ '!' '(' -group system -o -group security -o -group bin -o -group sys -o -group adm -o -group uucp -o -group mail -o -group printq -o -group cron -o -group audit -o -group shutdown -o -group ecs -o -group imnadm -o -group ipsec -o -group ipsec -o -group ldap -o -group lp -o -group haemrm -o -group snapp -o -group hacmp')' \ -ls

ABove is the sequence of commands that I am trying to execute. The problem is , if the find command does not find any *.a file whose owner is one of the system userids which we have mentioned in the comamnd sequence above , then it stops execution with an error message( User does not exist) and does not get further.Ideally we want the command sequence above to dispaly those *.a files which are owned by general userids other than the system userids mentioned above.Is there any way of ignoring this error message to continue the execution till the end .?