CLI Question - Add Users to group per Scrip

Hi,

Again just another question for the CLI Part. Has anyone a idea how to add a
set of users per scrip to a group?

Lets say, i have a list of 500 User that are needed to be member of a single
group?
With kindest regards

Torsten Brumm
Kuehne + Nagel
Datacenter Hamburg
Bauerbergweg 25
22111 Hamburg

Tel: +49 40 3033 33 199
Fax: +49 40 3033 344 3199
Gsm: +49 40 176 27 27 18 50
Mail: torsten.brumm@kuehne-nagel.com
Web: www.kuehne-nagel.com

Hi,

Again just another question for the CLI Part. Has anyone a idea how to add a
set of users per scrip to a group?

Lets say, i have a list of 500 User that are needed to be member of a single
group?

This isn’t a direct answer, but several months ago I was wrestling with
a similar issue of users and groups. Although I’m sure I could hammer
in some code to do this, after reading through the REST code, I started
thinking about what would be involved in a REST2 interface, something
that would provide more structure for extensions or modifications
on the server end.

I haven’t coded anything yet, but I did write up some notes
on what a new wire protocol and code organization might be like.

 http://tigger.uic.edu/~bobg/rt_api.html

Comments are welcome. I’m mostly convinced, but not 100%
sure this is a good way to go. And probably my notes
would change if/when I start building this.

 bobg

Again just another question for the CLI Part. Has anyone a idea how to add a
set of users per scrip to a group?

Lets say, i have a list of 500 User that are needed to be member of a single
group?

I did something similar via a full perl script (as opposed to using the
CLI). Here are some excerpts (untested in this form):

#!/usr/bin/perl -w

use strict;
use lib “/opt/rt3/lib”;

use RT;
use RT::Interface::CLI qw(CleanEnv GetCurrentUser);
use RT::Group;
use RT::User;

CleanEnv();
RT::LoadConfig();
RT::Init();

my($groupname) = ‘FooBar’;
my($group) = RT::Group->new($RT::SystemUser);
$group->LoadUserDefinedGroup($groupname);
die qq([ERROR] Cannot load group “$groupname”\n) unless $group->id;

my(@users) = GetListOfUsernames();
foreach my $username (@users) {
my($user) = RT::User->new($RT::SystemUser);
$user->Load($username);
die qq([ERROR] Could not load user “$username” – see log for
details\n) unless $user->id;

my($status, $msg) = $Groups->{$groupname}->AddMember($user->id);
die qq([ERROR] Cannot add user "$id" to group "$groupname" - $msg\n) 

unless $status;
}

Regards,

joe
Joe Casadonte
joe.casadonte@oracle.com

========== ==========
== The statements and opinions expressed here are my own and do not ==
== necessarily represent those of Oracle Corporation. ==
========== ==========

Hi Joe,

thats exactly what i’m looking for.

Just a small question to this scrip:

my(@users) = GetListOfUsernames();

Do you get with this a list from RT Users Table ?

Thanks

Torsten2007/2/15, Joe Casadonte joe.casadonte@oracle.com:

On 2/15/2007 11:04 AM, Torsten Brumm | Kuehne + Nagel wrote:

Again just another question for the CLI Part. Has anyone a idea how to
add a
set of users per scrip to a group?

Lets say, i have a list of 500 User that are needed to be member of a
single
group?

I did something similar via a full perl script (as opposed to using the
CLI). Here are some excerpts (untested in this form):

#!/usr/bin/perl -w

use strict;
use lib “/opt/rt3/lib”;

use RT;
use RT::Interface::CLI qw(CleanEnv GetCurrentUser);
use RT::Group;
use RT::User;

CleanEnv();
RT::LoadConfig();
RT::Init();

my($groupname) = ‘FooBar’;
my($group) = RT::Group->new($RT::SystemUser);
$group->LoadUserDefinedGroup($groupname);
die qq([ERROR] Cannot load group “$groupname”\n) unless $group->id;

my(@users) = GetListOfUsernames();
foreach my $username (@users) {
my($user) = RT::User->new($RT::SystemUser);
$user->Load($username);
die qq([ERROR] Could not load user “$username” – see log for
details\n) unless $user->id;

my($status, $msg) = $Groups->{$groupname}->AddMember($user->id);
die qq([ERROR] Cannot add user "$id" to group "$groupname" - $msg\n)

unless $status;
}


Regards,

joe
Joe Casadonte
joe.casadonte@oracle.com

========== ==========
== The statements and opinions expressed here are my own and do not ==
== necessarily represent those of Oracle Corporation. ==
========== ==========


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

MFG

Torsten Brumm

http://www.torsten-brumm.de

my(@users) = GetListOfUsernames();

Do you get with this a list from RT Users Table ?

Well, for me I was reading the names out of an Excel file, creating the
users first, and then adding them to a bunch of different groups. I
guess what I’m saying is that the implementation of GetListOfUsernames()
is left as an exercise for the reader… :slight_smile:

Regards,

joe
Joe Casadonte
joe.casadonte@oracle.com

========== ==========
== The statements and opinions expressed here are my own and do not ==
== necessarily represent those of Oracle Corporation. ==
========== ==========

Hi Joe,

your scrip looks fine so far, but i get a strange error message:

[Tue Feb 27 12:29:07 2007] [crit]: Can’t call method “AddMember” on an
undefined value at AddUsersToGroups.pl line 38. (/opt/rt36/lib/RT.pm:346)
Can’t call method “AddMember” on an undefined value at
AddUsersToGroups.plline 38.

And line 38 looks like:

my($status, $msg) = $group->{$groupname}->AddMember($user->id);
I’m not sure if the AddMember is defined in this routine, but i found:
SetMemberId VALUEhttp://rt36-messenger.int.kn/Developer/Perldoc/Body.html?n=RT::GroupMember#___top

Have you tried it?

Torsten2007/2/15, Joe Casadonte joe.casadonte@oracle.com:

On 2/15/2007 11:04 AM, Torsten Brumm | Kuehne + Nagel wrote:

Again just another question for the CLI Part. Has anyone a idea how to
add a
set of users per scrip to a group?

Lets say, i have a list of 500 User that are needed to be member of a
single
group?

I did something similar via a full perl script (as opposed to using the
CLI). Here are some excerpts (untested in this form):

#!/usr/bin/perl -w

use strict;
use lib “/opt/rt3/lib”;

use RT;
use RT::Interface::CLI qw(CleanEnv GetCurrentUser);
use RT::Group;
use RT::User;

CleanEnv();
RT::LoadConfig();
RT::Init();

my($groupname) = ‘FooBar’;
my($group) = RT::Group->new($RT::SystemUser);
$group->LoadUserDefinedGroup($groupname);
die qq([ERROR] Cannot load group “$groupname”\n) unless $group->id;

my(@users) = GetListOfUsernames();
foreach my $username (@users) {
my($user) = RT::User->new($RT::SystemUser);
$user->Load($username);
die qq([ERROR] Could not load user “$username” – see log for
details\n) unless $user->id;

my($status, $msg) = $Groups->{$groupname}->AddMember($user->id);
die qq([ERROR] Cannot add user "$id" to group "$groupname" - $msg\n)

unless $status;
}


Regards,

joe
Joe Casadonte
joe.casadonte@oracle.com

========== ==========
== The statements and opinions expressed here are my own and do not ==
== necessarily represent those of Oracle Corporation. ==
========== ==========


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

MFG

Torsten Brumm

http://www.torsten-brumm.de

And line 38 looks like:

my($status, $msg) = $group->{$groupname}->AddMember($user->id);
I’m not sure if the AddMember is defined in this routine, but i found:

Cut and paste error on my part. I think that line should read:

my($status, $msg) = $group->AddMember($user->id);

Regards,

joe
Joe Casadonte
joe.casadonte@oracle.com

========== ==========
== The statements and opinions expressed here are my own and do not ==
== necessarily represent those of Oracle Corporation. ==
========== ==========

Hi Joe,

Thanks, it works very well, you saved my many hours of work!!! I owe you a
beer!

TorstenOn 28.02.2007 14:53 Uhr, “Joe Casadonte” joe.casadonte@oracle.com wrote:

On 2/27/2007 7:15 AM, Torsten Brumm wrote:

And line 38 looks like:

my($status, $msg) = $group->{$groupname}->AddMember($user->id);
I’m not sure if the AddMember is defined in this routine, but i found:

Cut and paste error on my part. I think that line should read:

my($status, $msg) = $group->AddMember($user->id);

With kindest regards

KÜHNE+NAGEL (AG & Co.) KG
Torsten Brumm / HAM MI-ID
Datacenter Hamburg
Bauerbergweg 25
22111 Hamburg

Tel: +49 40 3033 33 199
Fax: +49 40 3033 344 3199
Gsm: +49 40 176 27 27 18 50
Mail: torsten.brumm@kuehne-nagel.com
Web: www.kuehne-nagel.com

Kühne + Nagel (AG & Co.) KG,
Geschäftsleitung: Hans-Georg Brinkmann (Vors.), Uwe Bielang (Stellv.), Dr.
Björn Johansson (Stellv.), Bruno Mang, Alfred Manke, Thorsten Meincke, Mark
Reinhardt (Stellv.), Tim Scharwath, Jens Wollensen

Sitz: Bremen, Registergericht: Bremen, HRA 21928, USt-IdNr.: DE 812773878,

Persönlich haftende Gesellschaft: Kühne & Nagel A.G., Sitz:
Contern/LuxemburgGeschäftsführender Verwaltungsrat: Klaus-Michael Kühne