Help on capturing /etc/group info.....!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on capturing /etc/group info.....!!
# 1  
Old 12-01-2009
MySQL Help on capturing /etc/group info.....!!

Gurus

I am trying to capture all the data in /etc/group file in a CSV ,thru a fingerprinting engine.

For hosts having ,unique group names and Ids ,following code works fine.

Trouble starts when on a host,there are multiple groups defined with same name and id.

e.g One of my hosts has 8 groups defined with [same]name "operators" and [same] id "542".

Query1:
How can i capture all these 8 groups with following script lines?

Query2:
Code:
myHost        operators  542     jackS johnM 2009-12-01

I am getting two names in the third column (userlist).'jackS' is where first group entry ends and 'johnM' is where second or next entry begins.
How can this be avoided?

Query3:
Is it possible to define multiple groups with same name and id?

Code:
Family Name:Host etcGroup

DUP:
cat /etc/group | awk -F':' '{print $1$3}'

GroupName:
A=`cat /etc/group |awk -F':' '{if ($1$3 == "@@Host etcGroup.DUP@@" ) print $1}'|sort|uniq`
echo $A

GID:
A=`cat /etc/group |awk -F':' '{if ($1$3 == "@@Host etcGroup.DUP@@" ) print $3}'|sort|uniq`
echo $A


Userlist:
A=`cat /etc/group|awk -F':' '{if ($1$3 == "@@Host etcGroup.DUP@@" ) print $4}'|sort|uniq`

B=`echo $A|wc -w`

if [ $B = 0 ]
then
echo NULL
else
count=`echo $A| nawk -F, {'print NF'}`
i=1
while [ $i -le $count ]
do
str[$i]=`echo $A| cut -d, -f${i}`
echo "${str[$i]}"
i=`expr $i + 1`
done
fi

Regards
Abhi
# 2  
Old 12-01-2009
Please post a bigger part of the input file (including the problematic records you mentioned) and an example of the expected output.
# 3  
Old 12-01-2009
MySQL

input here is : /etc/group file.

probably i got partial answer to first query by appending 'sort -u' at the end...but as you can see 'user6 user7' is still a problem....

I'll state an example here:

Code:
hostname  Groupname GID Userlist Date
myHost	operators	 542 542 542 542 542 542 542 542	user1	24/11/2009
myHost	operators	 542 542 542 542 542 542 542 542	user2	24/11/2009
myHost	operators	 542 542 542 542 542 542 542 542	user3	24/11/2009
myHost	operators	 542 542 542 542 542 542 542 542	user4	24/11/2009
myHost	operators	 542 542 542 542 542 542 542 542	user5	24/11/2009
myHost	operators	 542 542 542 542 542 542 542 542	user6 user7	24/11/2009

expected is:

Code:
myHost	operators	 542 user1	24/11/2009
myHost	operators	 542 user2	24/11/2009
myHost	operators	 542 user3	24/11/2009
myHost	operators	 542 user4	24/11/2009
myHost	operators	 542 user5	24/11/2009
myHost	operators	 542 user6 	24/11/2009
myHost	operators	 542 user7 	24/11/2009

Regards
Abhi
# 4  
Old 12-01-2009
Thanks,
and the expected output should be ... ?

---------- Post updated at 03:46 PM ---------- Previous update was at 03:27 PM ----------

Code:
awk -F'\t' 'NR == 1 { print; next }
{ split($3, g, /  */)
  if (n = split($4, u, /  */)) 
    for (i=1; i<=n; i++) print $1, $2, g[2], u[i], $5
  else print $1, $2, g[2], $4, $5 }
  ' OFS='\t' infile

You may need to adjust the spaces/tabs for your needs.
# 5  
Old 12-01-2009
MySQL

Thanks for that !!

Unfortunately i can't use this as

1> i do not wish to change code lines much just to get a new row...

2> i already wrote to capture exactly what i wanted....i need to tweak something somewhere to avoid my issue....

3> your code is to be run directly from command prompt where i need to put it in an engine where i m guessing it might not work....


even i had written something like this bfor..

Code:
cat /etc/group | \
nawk '
{
   ABC  = split($0, field, ":");
   USERS = split(field[4],user, ",");
   if (USERS == 0) printf "%s\t%s\t%s\n", field[1], field[3], "NULL";
   for (i = 1; i <= USERS; i++)
       printf "%s\t%s\t%s\n", field[1], field[3], user[i];
}
'

but this can be run easily from shell ,one time....my engine keeps re-iterating over DUP value....

Thanks for the effort and suggestion !!

Regards
Abhi
# 6  
Old 12-01-2009
If I understand correctly your code doesn't work and you don't want to use mine.
So post a sample of the original input file, your /etc/group file.
There are many helpful people here, they will help you with your task.

I'm sure that now you understand how important it is to post the complete requirement since the beginning Smilie

Last edited by radoulov; 12-01-2009 at 11:30 AM.. Reason: grammar ...
# 7  
Old 12-01-2009
MySQL

Probably you misunderstood....my code works fine for most of the hosts...with some ,i am having issue.

thats why i had asked the 'third' query.....

Secondly i can't explain how the engine works....i explained it once on this forum and luckily i got the right feedback...today i don have time to do that again....

whether you understood my requirement or not...i really can't help as ,i said before,explaining how engine works is tiring....thanks for trying though !!

i needed help in tweaking my existing code...which is working fine for over 1000+ hosts...i can't change it drastically for few hosts....

Regards
Abhi
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Printing the user and group info

Hi All, i want to collect all the users info whose id greater than 999 and print the groups information which they belong. example : for user in $(cut -d: -f1,3 /etc/passwd | egrep ':{4}$' | cut -d: -f1); do groups $user; done centos : centos adm wheel systemd-journal balu : balu ... (2 Replies)
Discussion started by: balu1234
2 Replies

2. Programming

Sql ORA-00937: not a single-group group function

I'm trying to return only one row with the highest value for PCT_MAX_USED. Any suggestions? When I add this code, I get the ORA-00937 error. trunc(max(decode( kbytes_max, 0, 0, (kbytes_alloc/kbytes_max)*100))) pct_max_used This is the original and returns all rows. select (select... (3 Replies)
Discussion started by: progkcp
3 Replies

3. Red Hat

Samba/Winbind issue - Can't get user and group info from sub domains

Hi, We now have a Samba or Winbind issue. The Linux client under RHEL6 can not get Windows' AD sub-domain info. See the following output please. The main domain 'Global' is shown online, but the sub-domain 'Europe' and 'Asia' are shown offline although they are online. Commands 'wbinfo -u' and... (0 Replies)
Discussion started by: aixlover
0 Replies

4. 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

5. 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

6. Shell Programming and Scripting

capturing info between words.

Dear Friends, I am facing 2 problems while writing a script 1) I have a flat file and I want to captur specific information from it. Example I have this string in the file PACK: P42 77 UNPACK: MHTT DMK I want to capture whatever is between word PACK: and word UNPACK: including... (8 Replies)
Discussion started by: anushree.a
8 Replies

7. Shell Programming and Scripting

Merge group numbers and add a column containing group names

Hi All I do have a file like this with 6 columns. Groups of data merge together and the group number is indicated above each group. 1 1 12 26 289 3.2e-027 GCGTATGGCGGC 2 12 26 215 6.7e+006 TTCCACCTTTTG 3 9 26 175 ... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

8. Solaris

Secondary group info source

Experts, I know when I use id it shows only the primary group information for the given user, and that info comes from passwd file. When I use groups it shows all groups user are member of, however from where come information given by groups command? grep fmtt3990 /etc/passwd... (6 Replies)
Discussion started by: fmattos
6 Replies

9. Shell Programming and Scripting

Merge group numbers and add a column containing group names

I have a file in the following format. Groups of data merge together and the group number is indicated above each group. 1 adrf dfgr dfg 2 dfgr dfgr 3 dfef dfr fd 4 fgrt fgr fgg 5 fgrt fgr (3 Replies)
Discussion started by: Lucky Ali
3 Replies
Login or Register to Ask a Question