grep group and passwd file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep group and passwd file
# 1  
Old 07-16-2003
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?
# 2  
Old 07-16-2003
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
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
Hhhm, let's start a perl course Smilie
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 10:47 PM..
# 5  
Old 07-17-2003
And if you still want to try awk:
Code:
awk -F":" '{print $1}' < /etc/group |
while read USR
do
 grep $USR /etc/password
done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep patterns and group counts

Hi, I have a continuous log file which has the following format:- 02/Sep/2015: IP 11.151.108.166 error occurred etc 03/Sep/2015: IP 11.151.108.188 error occurred etc 03/Sep/2015: IP 11.152.178.250 error occurred etc 03/Sep/2015: IP 11.188.108.176 error occurred etc 03/Sep/2015: IP... (4 Replies)
Discussion started by: finn
4 Replies

2. UNIX for Dummies Questions & Answers

Conflicting GID in group and passwd files.

Hi guys, I have a question. In the passwd file, user johndoe has a GID of 100 which is the group named users in the group file. But if you check the group file, johndoe is not listed under GID 100, but under GID 33, which is the group named videos. Under what group does johndoe really belong,... (1 Reply)
Discussion started by: goldenlight1814
1 Replies

3. Shell Programming and Scripting

need a one liner to grep a group info from /etc/group and use that result to search passwd file

/etc/group tiadm::345:mk789,po312,jo343,ju454,ko453,yx879,iy345,hn453 bin::2:root,daemon sys::3:root,bin,adm adm::4:root,daemon uucp::5:root /etc/passwd mk789:x:234:1::/export/home/dummy:/bin/sh po312:x:234:1::/export/home/dummy:/bin/sh ju454:x:234:1::/export/home/dummy:/bin/sh... (6 Replies)
Discussion started by: chidori
6 Replies

4. UNIX for Dummies Questions & Answers

Inconsistency between passwd and group

Hi, I have a passwd file with 3 users belonging to the the root group (gid=0), but the group file does not list these users as members of the root group? Shoud I be worried and apart from manually changing it, how can it be remediated? thx Norgaard (1 Reply)
Discussion started by: Norgaard
1 Replies

5. UNIX for Dummies Questions & Answers

Understanding group and passwd

Hi, I am checking who belong to the dba group , and found that oracle and autosys users are part of this group cat /etc/group | grep dba dba::400:oracle,autosys I thought to found user autosys under group 400 togther with user oracle , but found it in group 1000 as you can see bellow.... (2 Replies)
Discussion started by: yoavbe
2 Replies

6. Shell Programming and Scripting

Sort the file contents in each group....print the group title as well

I've this file and need to sort the data in each group File would look like this ... cat file1.txt Reason : ABC 12345-0023 32123-5400 32442-5333 Reason : DEF 42523-3453 23345-3311 Reason : HIJ 454553-0001 I would like to sort each group on the last 4 fileds and print them... (11 Replies)
Discussion started by: prash184u
11 Replies

7. UNIX for Dummies Questions & Answers

Grep group by and count

Hi, I have several files with same filename pattern. I want to calculate count of individual files using grep/egrep. Let me be more descriptive In directory E1 i have files like ab_20091201_12:24 ab_20091201_03:24 cd_20091201_04:16 cd_20091203_08:34 ef_20091201_06:12 ef_20091201 Now i want... (3 Replies)
Discussion started by: shounakboss
3 Replies

8. Shell Programming and Scripting

cat /etc/passwd and grep -v on /etc/shells

Hi All, I'd like to do this cat /etc/passwd and grep -v on the /etc/shells list I'd like to find all shell that doesn't exist on the /etc/passwd. Is there an easy way without doing a egrep -v "/bin/sh|/bin/bash................"? How do I use a file /etc/shells as my list for... (4 Replies)
Discussion started by: itik
4 Replies

9. Shell Programming and Scripting

ypcat group, ypcat passwd

When i run the following command on our server ypcat group or ypcat passwd I get list of groups and users respectively. I am not sure whether this list is only for the groups or users on the particular server on which i executed the command or all the groups and users on all the servers in... (2 Replies)
Discussion started by: pinnacle
2 Replies

10. UNIX for Dummies Questions & Answers

is it really not possible for me to edit the etc/group & the etc/passwd files?

From what I have read it possible to create a new group by editing the etc/group and etc/passwd in UNIX two files but a non-experienced user may face many problems such as destroying the file by mistake ot that his changes to these file does not make any difference. However, there is this... (2 Replies)
Discussion started by: whatev3r
2 Replies
Login or Register to Ask a Question