The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-16-2003
Registered User
 

Join Date: Jul 2003
Posts: 2
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  
Old 07-16-2003
oombera's Avatar
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
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
where $1 is the field the username is in, inside the /etc/group file...

if the /etc/group file looks like:
xxx xxx jsmith xxx
then you'd use {print $3}
  #3  
Old 07-17-2003
Registered User
 

Join Date: Jul 2003
Posts: 2
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  
Old 07-17-2003
davidg's Avatar
Registered User
 

Join Date: Jul 2003
Location: Holland
Posts: 207
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";
  }
}
It's tested and works !!

Regs David

Last edited by oombera; 02-18-2004 at 07:47 PM.
  #5  
Old 07-17-2003
oombera's Avatar
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0