Discussion:
[p4] admin - removing user from multiple groups
s***@symbian.com
2006-02-24 11:27:24 UTC
Permalink
Hi

Anyone got a Perl or Python script that removes a user from being a
member of multiple groups, its part of a housekeeping excersise, just got
lots to do quickly, and not being a very good script writer at all it'll
take me longer to write it myself than do the work, so thought I'd ask
those that are good, or may have one already :-)

Many thanks

Sally Page
Configuration Management Engineer, Delivery Services
Symbian Software (UK) Ltd
Direct: +44 (0) 20 7154 1912
Mobile: +44 (0) 7769 588915



-----------------------------------------
**********************************************************************
Symbian Software Ltd is a company registered in England and Wales with
registered number 4190020 and registered office at 2-6 Boundary Row,
Southwark, London, SE1 8HP, UK. This message is intended only for use by
the named addressee and may contain privileged and/or confidential
information. If you are not the named addressee you should not disseminate,
copy or take any action in reliance on it. If you have received this
message in error please notify ***@symbian.com and delete the
message and any attachments accompanying it immediately. Neither Symbian
nor any of its Affiliates accepts liability for any corruption,
interception, amendment, tampering or viruses occurring to this message in
transit or for any message sent by its employees which is not in compliance
with Symbian corporate policy.
**********************************************************************
Weintraub, David
2006-02-24 18:34:31 UTC
Permalink
Here's a simple shell script that counts the number of groups each user
is in:

p4 users | awk '{print $1}' | while read user
do
printf "User %s: " $user
p4 groups $user | wc -l
done

The question I have is what if you find a user is in more than one
group? Which group do they stay in? Anyway, this will give you a start.

-----Original Message-----
From: perforce-user-***@perforce.com
[mailto:perforce-user-***@perforce.com] On Behalf Of
***@symbian.com
Sent: Friday, February 24, 2006 6:27 AM
To: perforce-***@perforce.com
Subject: [p4] admin - removing user from multiple groups

Hi

Anyone got a Perl or Python script that removes a user from being a
member of multiple groups, its part of a housekeeping excersise, just
got lots to do quickly, and not being a very good script writer at all
it'll take me longer to write it myself than do the work, so thought I'd
ask those that are good, or may have one already :-)

Many thanks

Sally Page
Configuration Management Engineer, Delivery Services Symbian Software
(UK) Ltd
Direct: +44 (0) 20 7154 1912
Mobile: +44 (0) 7769 588915



-----------------------------------------
**********************************************************************
Symbian Software Ltd is a company registered in England and Wales with
registered number 4190020 and registered office at 2-6 Boundary Row,
Southwark, London, SE1 8HP, UK. This message is intended only for use
by the named addressee and may contain privileged and/or confidential
information. If you are not the named addressee you should not
disseminate, copy or take any action in reliance on it. If you have
received this message in error please notify ***@symbian.com and
delete the message and any attachments accompanying it immediately.
Neither Symbian nor any of its Affiliates accepts liability for any
corruption, interception, amendment, tampering or viruses occurring to
this message in transit or for any message sent by its employees which
is not in compliance with Symbian corporate policy.
**********************************************************************
_______________________________________________
perforce-user mailing list - perforce-***@perforce.com
http://maillist.perforce.com/mailman/listinfo/perforce-user
Jamison, Shawn
2006-02-24 18:39:08 UTC
Permalink
Well, Yes!
Both of these came from this forum.

I have modified them a little for my needs so you will have to muddle with them to suit you.

One warning. Backup your current group definitions if they are not already in a UserSpec depot.

-Shawn J>


-----Original Message-----
From: perforce-user-***@perforce.com
[mailto:perforce-user-***@perforce.com]On Behalf Of
***@symbian.com
Sent: Friday, February 24, 2006 6:27 AM
To: perforce-***@perforce.com
Subject: [p4] admin - removing user from multiple groups


Hi

Anyone got a Perl or Python script that removes a user from being a
member of multiple groups, its part of a housekeeping excersise, just got
lots to do quickly, and not being a very good script writer at all it'll
take me longer to write it myself than do the work, so thought I'd ask
those that are good, or may have one already :-)

Many thanks

Sally Page
Configuration Management Engineer, Delivery Services
Symbian Software (UK) Ltd
Direct: +44 (0) 20 7154 1912
Mobile: +44 (0) 7769 588915



-----------------------------------------
**********************************************************************
Symbian Software Ltd is a company registered in England and Wales with
registered number 4190020 and registered office at 2-6 Boundary Row,
Southwark, London, SE1 8HP, UK. This message is intended only for use by
the named addressee and may contain privileged and/or confidential
information. If you are not the named addressee you should not disseminate,
copy or take any action in reliance on it. If you have received this
message in error please notify ***@symbian.com and delete the
message and any attachments accompanying it immediately. Neither Symbian
nor any of its Affiliates accepts liability for any corruption,
interception, amendment, tampering or viruses occurring to this message in
transit or for any message sent by its employees which is not in compliance
with Symbian corporate policy.
**********************************************************************
_______________________________________________
perforce-user mailing list - perforce-***@perforce.com
http://maillist.perforce.com/mailman/listinfo/perforce-user
Wright, Richard
2006-02-24 19:59:24 UTC
Permalink
By the way, if you are using a recent version of Perforce (2004.2+, I
believe), you can count how many groups a user is in with the following:

p4 -ztag groups | grep user | sort | uniq -c

For anyone looking to attack this problem or similar problems, take a look a
the -ztag (or -G or -R for Python or Ruby) output of p4 groups in the recent
servers. You can get a great deal of info out of it quickly.

-Rick

-----Original Message-----
From: perforce-user-***@perforce.com
[mailto:perforce-user-***@perforce.com]On Behalf Of Weintraub, David
Sent: Friday, February 24, 2006 10:35 AM
To: ***@symbian.com; perforce-***@perforce.com
Subject: Re: [p4] admin - removing user from multiple groups


Here's a simple shell script that counts the number of groups each user
is in:

p4 users | awk '{print $1}' | while read user
do
printf "User %s: " $user
p4 groups $user | wc -l
done

The question I have is what if you find a user is in more than one
group? Which group do they stay in? Anyway, this will give you a start.

-----Original Message-----
From: perforce-user-***@perforce.com
[mailto:perforce-user-***@perforce.com] On Behalf Of
***@symbian.com
Sent: Friday, February 24, 2006 6:27 AM
To: perforce-***@perforce.com
Subject: [p4] admin - removing user from multiple groups

Hi

Anyone got a Perl or Python script that removes a user from being a
member of multiple groups, its part of a housekeeping excersise, just
got lots to do quickly, and not being a very good script writer at all
it'll take me longer to write it myself than do the work, so thought I'd
ask those that are good, or may have one already :-)

Many thanks

Sally Page
Configuration Management Engineer, Delivery Services Symbian Software
(UK) Ltd
Direct: +44 (0) 20 7154 1912
Mobile: +44 (0) 7769 588915



-----------------------------------------
**********************************************************************
Symbian Software Ltd is a company registered in England and Wales with
registered number 4190020 and registered office at 2-6 Boundary Row,
Southwark, London, SE1 8HP, UK. This message is intended only for use
by the named addressee and may contain privileged and/or confidential
information. If you are not the named addressee you should not
disseminate, copy or take any action in reliance on it. If you have
received this message in error please notify ***@symbian.com and
delete the message and any attachments accompanying it immediately.
Neither Symbian nor any of its Affiliates accepts liability for any
corruption, interception, amendment, tampering or viruses occurring to
this message in transit or for any message sent by its employees which
is not in compliance with Symbian corporate policy.
**********************************************************************
_______________________________________________
perforce-user mailing list - perforce-***@perforce.com
http://maillist.perforce.com/mailman/listinfo/perforce-user
_______________________________________________
perforce-user mailing list - perforce-***@perforce.com
http://maillist.perforce.com/mailman/listinfo/perforce-user
Noah Salzman
2006-02-24 20:03:08 UTC
Permalink
Post by s***@symbian.com
Anyone got a Perl or Python script that removes a user from being a
member of multiple groups, its part of a housekeeping excersise, just got
lots to do quickly, and not being a very good script writer at all it'll
take me longer to write it myself than do the work, so thought I'd ask
those that are good, or may have one already :-)
Will you take a shell script?


#!/bin/sh

DEL_USER=$1
TMP_FILE=/tmp/p4_group_tmp
RC=1
p4 groups > $TMP_FILE

echo ""
echo "WARNING: This script will delete user '$DEL_USER' from all
groups."
echo ""
echo "Type 'n' to get a list of groups for '$DEL_USER' and do nothing
else."
echo "Type 'y' to actually delete '$DEL_USER' from each group."

read RESPONSE

if [ "x$RESPONSE" != "xy" ]; then
echo ""
echo "No changes were made."
echo "Here are the groups that contain '$DEL_USER':"

while read LINE
do
p4 group -o $LINE | grep $DEL_USER > /dev/null
RC=$?
if [ $RC -eq 0 ]; then
echo $LINE
fi
done < $TMP_FILE
echo ""
exit 0
else
while read LINE
do
p4 group -o $LINE | grep $DEL_USER > /dev/null
RC=$?
if [ $RC -eq 0 ]; then
echo ""
echo "Deleting '$DEL_USER' from group $LINE ..."
p4 group -o $LINE | sed s/$DEL_USER// | p4 group -i
fi
done < $TMP_FILE

echo ""
exit 0
fi

#end
Noah Salzman
2006-02-24 21:48:19 UTC
Permalink
There was a bug in the first posting of the script where grep would
match on "jsmithe" when you had specified "jsmith". I changed it to
egrep. Doh!

Here is version 2:


#!/bin/sh

DEL_USER=$1
TMP_FILE=/tmp/p4_group_tmp
RC=1
p4 groups > $TMP_FILE

echo ""
echo "WARNING: This script will delete user '$DEL_USER' from all
groups."
echo ""
echo "Type 'n' to get a list of groups for '$DEL_USER' and do nothing
else."
echo "Type 'y' to actually delete '$DEL_USER' from each group."

read RESPONSE

if [ "x$RESPONSE" != "xy" ]; then
echo ""
echo "No changes were made."
echo "Here are the groups that contain '$DEL_USER':"

while read LINE
do
p4 group -o $LINE | egrep "^.$DEL_USER$" > /dev/null
RC=$?
if [ $RC -eq 0 ]; then
echo $LINE
fi
done < $TMP_FILE
echo ""
exit 0
else
while read LINE
do
p4 group -o $LINE | egrep "^.$DEL_USER$" > /dev/null
RC=$?
if [ $RC -eq 0 ]; then
echo ""
echo "Deleting '$DEL_USER' from group $LINE ..."
p4 group -o $LINE | sed s/$DEL_USER// | p4 group -i
fi
done < $TMP_FILE

echo ""
exit 0
fi

#end
Ivey, William
2006-02-24 21:16:56 UTC
Permalink
Yeah, ztag is cool. I was playing around with it a while back to
check my groups and used this line (one line no matter what
word wrap thinks):

p4 -ztag groups | sed -n -e "/^\.\.\. user/!d;s|^\.\.\. user ||;N;s|\n\.\.\. group | : |;p" | sort

(escape the ! as \! for c shells, works from the command prompt on
Windows if you have a sed in your path)

That just gives me a list sorted by user that looks like:

admingroup : buildgroup
admingroup : devgroup
albert : buildgroup
albert : devgroup
whivey : admingroup
xeno : devgroup
etc.

Note that "user" can be another group as well as a real user.
filtering that out is left as an exercise for the less lazy.

-Wm
Post by Weintraub, David
-----Original Message-----
By the way, if you are using a recent version of Perforce (2004.2+, I
believe), you can count how many groups a user is in with the
p4 -ztag groups | grep user | sort | uniq -c
Tetlow, Gordon
2006-02-24 22:06:48 UTC
Permalink
If you just want to see what groups the person is in, p4 groups
<username> works much easier.

-gordon
Post by Weintraub, David
-----Original Message-----
Sent: Friday, February 24, 2006 12:03 PM
Subject: Re: [p4] admin - removing user from multiple groups
Post by s***@symbian.com
Anyone got a Perl or Python script that removes a user from being a
member of multiple groups, its part of a housekeeping excersise,
just got
lots to do quickly, and not being a very good script writer at all
it'll
take me longer to write it myself than do the work, so
thought I'd ask
Post by s***@symbian.com
those that are good, or may have one already :-)
Will you take a shell script?
#!/bin/sh
DEL_USER=$1
TMP_FILE=/tmp/p4_group_tmp
RC=1
p4 groups > $TMP_FILE
echo ""
echo "WARNING: This script will delete user '$DEL_USER' from all
groups."
echo ""
echo "Type 'n' to get a list of groups for '$DEL_USER' and do
nothing
else."
echo "Type 'y' to actually delete '$DEL_USER' from each group."
read RESPONSE
if [ "x$RESPONSE" != "xy" ]; then
echo ""
echo "No changes were made."
echo "Here are the groups that contain '$DEL_USER':"
while read LINE
do
p4 group -o $LINE | grep $DEL_USER > /dev/null
RC=$?
if [ $RC -eq 0 ]; then
echo $LINE
fi
done < $TMP_FILE
echo ""
exit 0
else
while read LINE
do
p4 group -o $LINE | grep $DEL_USER > /dev/null
RC=$?
if [ $RC -eq 0 ]; then
echo ""
echo "Deleting '$DEL_USER' from group $LINE ..."
p4 group -o $LINE | sed s/$DEL_USER// |
p4 group -i
fi
done < $TMP_FILE
echo ""
exit 0
fi
#end
_______________________________________________
http://maillist.perforce.com/mailman/listinfo/perforce-user
Noah Salzman
2006-02-24 22:11:46 UTC
Permalink
Post by Tetlow, Gordon
If you just want to see what groups the person is in, p4 groups
<username> works much easier.
That's funny. I made it much harder than it needed to be. However,
for the delete part you'll still need some minimal loop.
Robert Cowham
2006-02-25 11:36:00 UTC
Permalink
Post by Tetlow, Gordon
If you just want to see what groups the person is in, p4
groups <username> works much easier.
Note that this isn't recursive which would be nice - though not relevant to
the point at hand:

P4 groups fred
Grp1

P4 groups grp1
Grp2

Would be nice perhaps to have a "p4 groups -a" option which showed group
membership recursively. (have raised support call)

Robert

Continue reading on narkive:
Loading...