[rt-users] CLI Question - Add Users to group per Scrip

Joe Casadonte joe.casadonte at oracle.com
Thu Feb 15 12:59:29 EST 2007


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 at oracle.com

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



More information about the rt-users mailing list