[rt-users] importing users

Garry T. Williams garry.williams at cbeyond.net
Fri Feb 2 09:45:28 EST 2007


On Friday 02 February 2007 07:44, Obando, David DE - EV wrote:
> Dear all,
> 
> I have a bunch of users (in a csv file) and would like to import
> them into RT. What is the best way to do it?

The Wiki is your friend.  :-)

I did it with code something like this (untested):

    #!/usr/bin/perl
    use strict;
    use warnings;

    use lib '/path/to/rt/lib';
    use RT::Interface::CLI;

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

    my $rt_user = RT::User->new($RT::SystemUser);
    while (<>) {
	my ($id, $name, $passwd, $email) = split /,/;

	my ($rc, $msg) =
	    $rt_user->Create(Name         => $id,
			     RealName     => $name,
			     Password     => $passwd,
			     EmailAddress => $email,
			     Privileged   => 1,
			    );
	unless ($rc) {
	    print "add user $id: $msg\n";
	}
    }

The split() is probably inadequate -- you might want to use
Text::ParseWords to be more robust.

After a user is added, you might want to include that user in a user
defined group (untested):

    my $rt_group = RT::Group->new($RT::SystemUser);
    $rt_group->LoadUserDefinedGroup('my_group_name');
    my ($rc, $msg) = $rt_group->AddMember($rt_user->PrincipalId());

    unless ($rc) {
	print "can't add $id to my_group_name: $msg\n";
    }

-- 
Garry T. Williams --- 678-370-2438






More information about the rt-users mailing list