![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A question on /etc/passwd file | ij_2005 | SUN Solaris | 2 | 04-16-2008 11:55 PM |
| help in /etc/passwd file | useless79 | Shell Programming and Scripting | 4 | 09-19-2007 02:23 AM |
| /etc/passwd file | s_mad010 | Security | 4 | 12-06-2005 05:14 AM |
| Help! passwd file corrupted | Tony Montana | UNIX for Dummies Questions & Answers | 2 | 05-21-2005 05:45 AM |
| passwd file contents | kswaraj | UNIX for Dummies Questions & Answers | 5 | 07-07-2004 08:32 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
grep group and passwd file
How can I find find all members in the /etc/password file that belong to the dba group in the /etc/group file?
|
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
I don't have a box in front of me, but maybe you could post a couple sample lines from each one? Also, what system/shell do you use?
It'd have to be something like: Code:
awk '{print $1}' < /etc/group |
while read USR
do
grep $USR /etc/password
done
if the /etc/group file looks like: xxx xxx jsmith xxx then you'd use {print $3} |
|
#3
|
|||
|
|||
|
Thanks!
i use ksh here's a few lines from /etc/group root::0:root other::1:root,hpdb bin::2:root,bin sys::3:root,uucp dba::101: here's a fre lines from /etc/passwd root:IVDV6376kipOA:0:3::/:/sbin/sh bin:*:2:2::/usr/bin:/sbin/sh sys:*:3:3::/: oracle:rbQbnl8j2tfx6:101:101:,,,:/oratest2/u01/app/oracle:/bin/gsh bmc:xbYoHEN598qAc:141:20:BMC Group Id,,,:/home/bmc:/bin/gsh joew:UpWBpbMeEg/WM:20828:101:Joe West:/home/jwest:/bin/gsh |
|
#4
|
||||
|
||||
|
Hhhm, let's start a perl course
Code:
#!/usr/local/bin/perl
$dba="101";
open(FH, "< /tmp/passwd");
@lines=<FH>;
close(FH);
foreach $line(@lines) {
$group = ( split /:/, $line)[3];
if ( "$group" == "$dba" ) {
print "Group is DBA \n";
print "$line \n";
}
}
Regs David Last edited by oombera; 02-18-2004 at 07:47 PM. |
|
#5
|
||||
|
||||
|
And if you still want to try awk:
Code:
awk -F":" '{print $1}' < /etc/group |
while read USR
do
grep $USR /etc/password
done
|
||||
| Google The UNIX and Linux Forums |