A while a go I needed to add a whole raft of users (about 400 or so 🙂 ) to our work RT system. Doing this manually had little appeal so I was looking for a scriptable way of doing it.
I found a script on the wiki ( wiki.bestpractical.com ) but it only supported populating RT from /etc/passwd entires. So close and yet… so with a pointer or two from Bunty, my handy online Perl guru friend 🙂 I managed to use the existing script and bodge it to allow command line arguements 🙂
#!/usr/bin/perl -w
#
# rtadduser: add a local user to RT
# David Maze
# $Id$
# Poorly modified by Tig to accept commandline arguments
# Known issues, will silently fail if a user already exists
BEGIN{
push @INC,"/usr/share/request-tracker3.6/lib/";
}
use lib "/usr/uns/lib";
use strict;
use English;
use RT::Interface::CLI qw(CleanEnv);
use RT::User;
use Getopt::Long;
my ($user, $passwd, $email);
GetOptions (
"user=s" => \$user,
"email=s" => \$email,
"passwd=s" => \$passwd
);
CleanEnv();
RT::LoadConfig();
RT::Init();
print("Creating user with the following variables\n");
print("user : $user\n");
print("e-mail : $email\n");
print("password : $passwd\n");
my $UserObj = new RT::User(RT::SystemUser);
$UserObj->Create(Name => $user,
EmailAddress => "$email",
Privileged => 1,
Password => $passwd
);
print("If there was no error it possibly worked!\n");
To use this you will need Getopt::Long installed, usage is :
perl rtadduser -user=username -email=user@foo.com -passwd=secretpassword
Oh and you will need to poke line 10 (the one with the path to RT.pm) for your distro.
I will put this onto the wiki soon, just needed to dump it somewhere indexable before I forget about it 🙂