Re: checking groups on unix
Hello Joni, Wednesday, June 27, 2001, PURMONEN, Joni [EMAIL PROTECTED] wrote: PJ I need to check the group status on numerous files/directories, and haven't PJ been able to fing out the best way to do it with perl. I simply need to see PJ if some directories do not have certain group set on them. PJ Can anyone give any pointers? if i correctly understand, you need 'stat' function. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($filename); perldoc -f stat Best wishes, Maximmailto:[EMAIL PROTECTED]
Re: checking groups on unix
How to build @files is left as an exercise for the reader. code foreach my $file (@files) { #getgrpid returns the group file entry for a given group id. my $groupname = (getgrgid((stat($file))[5]))[0]; if ($groupname != groupname) { print $file has bad groupname: $groupname\n; } } /code On 27 Jun 2001 09:59:07 +0100, PURMONEN, Joni wrote: Hi ya, I need to check the group status on numerous files/directories, and haven't been able to fing out the best way to do it with perl. I simply need to see if some directories do not have certain group set on them. Can anyone give any pointers? Cheers, Joni Ps. I only have learning perl and some other fairly simple books which didn't seem to have anything useful in them -- Today is Pungenday, the 32nd day of Confusion in the YOLD 3167 This statement is false.
Re: checking groups on unix
Check out the stat function -- it returns a long list of info., which will be of use to you: perl -e ' @list=stat(.); foreach(@list){printf %o \n,$_;} ' The printf %o part prints the value in octal, which is what you're after. The 3rd value in the returned array $list[2] is the mode. on my linux box, I get this output: 1406 644042 40775 27 1046 12 0 4000 7316040631 7315775540 7315775540 1 4 The 3rd element is the mode...775. ls -ald . shows: drwxrwxr-x 23 mcauthor wheel2048 Jun 25 23:02 Hope this helps. perldoc -f stat will give you all the nitty gritty on the rest. Chances are good your script will return much more useful information than you initially thought! Matt --- PURMONEN, Joni [EMAIL PROTECTED] wrote: Hi ya, I need to check the group status on numerous files/directories, and haven't been able to fing out the best way to do it with perl. I simply need to see if some directories do not have certain group set on them. Can anyone give any pointers? Cheers, Joni Ps. I only have learning perl and some other fairly simple books which didn't seem to have anything useful in them __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
RE: checking groups on unix
Since you're doing a string compare on $groupname, you need to use 'ne', not '!='. code foreach my $file (@files) { #getgrpid returns the group file entry for a given group id. my $groupname = (getgrgid((stat($file))[5]))[0]; if ($groupname ne groupname) { print $file has bad groupname: $groupname\n; } } /code (since foo == bar numerically) -Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 27, 2001 3:11 AM To: [EMAIL PROTECTED] Subject: Re: checking groups on unix How to build @files is left as an exercise for the reader. code foreach my $file (@files) { #getgrpid returns the group file entry for a given group id. my $groupname = (getgrgid((stat($file))[5]))[0]; if ($groupname != groupname) { print $file has bad groupname: $groupname\n; } } /code On 27 Jun 2001 09:59:07 +0100, PURMONEN, Joni wrote: Hi ya, I need to check the group status on numerous files/directories, and haven't been able to fing out the best way to do it with perl. I simply need to see if some directories do not have certain group set on them. Can anyone give any pointers? Cheers, Joni Ps. I only have learning perl and some other fairly simple books which didn't seem to have anything useful in them -- Today is Pungenday, the 32nd day of Confusion in the YOLD 3167 This statement is false.