The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
grep unix.com with google



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #8 (permalink)  
Old 12-01-2009
danmero danmero is offline Forum Advisor  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,519
Trying to improve radoulov solution

Code:
# cat /etc/group
hostname  Groupname GID Userlist Date
myHot   operaors         54 542 542 542 542 542 542 542 user1 user9     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

# awk -F'\t' 'NR>1{split($3, g, " ");n=split($4,u," ");for(i=0;++i<=n;){print $1,$2,g[1],u[i],$NF}next}1' OFS=\\t /etc/group
hostname  Groupname GID Userlist Date
myHot   operaors        54      user1   24/11/2009
myHot   operaors        54      user9   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

OP whould watch for Useless Use of Cat Award
  #9 (permalink)  
Old 12-02-2009
Registered User
 

Join Date: Apr 2008
Location: Mumbai,India
Posts: 97
Thumbs up

i'll reframe my problem...this should be easy to debug ...



Code:
bash-3.00$ A=`cat /etc/group|awk -F: '{if ($1$3 == "secur138"){print $NF}}'|sort|uniq`
bash-3.00$ echo $A
t9330sp,t0096pg,t6899bs,t2483eb,t1563dr,t6658pb t9330sp,t0096pg,t6899bs,t2483eb,t1563dr,t6658pb,smadmn,sysweb,root

See that green colored string....rest all strings(or members) are comma separated....whereas this string is not..it should have been t6658pb,t9330sp...

and its happening because


Code:
bash-3.00$  cat /etc/group|awk -F: '{if ($1$3 == "secur138"){print $NF}}'
t9330sp,t0096pg,t6899bs,t2483eb,t1563dr,t6658pb
t9330sp,t0096pg,t6899bs,t2483eb,t1563dr,t6658pb,smadmn,sysweb,root

i have two groups defined with same name and id ,but few diffrent members....

My code looks like following to capture these comma separated strings:


Code:
Host etcGroup DUP:

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


Userlist:

A=`cat /etc/group|awk -F: '{if ($1$3 == "@@Host etcGroup.DUP@@") {print $NF}}'|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


any ideas?

Regards
Abhi
  #10 (permalink)  
Old 12-03-2009
Registered User
 

Join Date: Apr 2008
Location: Mumbai,India
Posts: 97
Thumbs up

guys

any ideas/suggestions ?

Regards
Abhi
  #11 (permalink)  
Old 12-03-2009
TonyFullerMalv's Avatar
Registered User
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 933
To anwer your query:
Quote:
Query3:
Is it possible to define multiple groups with same name and id?
I use mutiple groups with the same GID but different names to get around the maximum string length problem, e.g.

Code:
group:x:1024:member1,member2,member3
groupa:x:1024:member4,member5,member6
groupb:x:1024:member7,member8,member9

If the have the same name then in Solaris only one of the lines would count, proof would be to run:

Code:
$ getent group <groupname>

To query the group that has two lines with the same name and GID using an OS call and see what gets listed.
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Secondary group info source fmattos SUN Solaris 6 12-01-2009 08:19 AM
Merge group numbers and add a column containing group names Lucky Ali Shell Programming and Scripting 3 11-20-2009 02:10 AM
retrieving all group names with a given group number Andrewkl UNIX for Advanced & Expert Users 3 10-25-2008 05:07 AM
Monkcast #12: IBM HW group OEMs Solaris to chagrin of SW group & a ... - ZDNet.com bl Linux Bot UNIX and Linux RSS News 0 08-17-2007 05:30 PM
entry in /etc/group too long - problem using sudo with %group poli SUN Solaris 4 12-21-2004 09:50 AM



All times are GMT -4. The time now is 10:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0