RT3BatchAddUsers: Difference between revisions
Jump to navigation
Jump to search
m (2 revisions imported) |
No edit summary |
||
Line 1: | Line 1: | ||
<syntaxhighlight lang="perl" line="1" > | |||
#!/usr/bin/perl -w | |||
# | # | ||
# rtadduser: Batch add local users to RT based on a csv file named users_data.csv located # in the same directory | # rtadduser: Batch add local users to RT based on a csv file named users_data.csv located # in the same directory | ||
Line 28: | Line 29: | ||
open(USERS_DATA, "./users_data.csv") || die("Could not open file!"); | open(USERS_DATA, "./users_data.csv") || die("Could not open file!"); | ||
@raw_data= | @raw_data=<USERS_DATA>; | ||
close(USERS_DATA); | close(USERS_DATA); | ||
foreach $bc_user (@raw_data) | foreach $bc_user (@raw_data) | ||
Line 36: | Line 37: | ||
my $UserObj = new RT::User(RT::SystemUser); | my $UserObj = new RT::User(RT::SystemUser); | ||
$UserObj->Create(Name = | $UserObj->Create(Name => $username, | ||
RealName = | RealName => $realname, | ||
EmailAddress = | EmailAddress => $email_address, | ||
Password = | Password => 'Passw0rd', | ||
Organization = | Organization => $organization, | ||
Address1 = | Address1 => $address1, | ||
City = | City => $city, | ||
Country = | Country => $country, | ||
Privileged = | Privileged => 1); | ||
} | } | ||
</ | |||
</syntaxhighlight> |
Revision as of 14:15, 21 March 2017
#!/usr/bin/perl -w
#
# rtadduser: Batch add local users to RT based on a csv file named users_data.csv located # in the same directory
# Mohamed El Erian <mohamed.elerian@britishcouncil.org.eg,melerian@gmail.com>
# Partly based on script provided by David Maze <dmaze@cag.lcs.mit.edu>
# File format is username,realname,email_address,organization,address1,city,country
# $Id$
#
use lib "/usr/lib";
use strict;
use English;
use RT::Interface::CLI qw(CleanEnv);
use RT::User;
CleanEnv();
RT::LoadConfig();
RT::Init();
my @raw_data;
my $bc_user = '';
my $username = '';
my $realname = '';
my $email_address = '';
my $organization = '';
my $address1 = '';
my $city = '';
my $country = '';
open(USERS_DATA, "./users_data.csv") || die("Could not open file!");
@raw_data=<USERS_DATA>;
close(USERS_DATA);
foreach $bc_user (@raw_data)
{
chop($bc_user);
($username,$realname,$email_address,$organization,$address1,$city,$country)=split(/\,/,$bc_user);
my $UserObj = new RT::User(RT::SystemUser);
$UserObj->Create(Name => $username,
RealName => $realname,
EmailAddress => $email_address,
Password => 'Passw0rd',
Organization => $organization,
Address1 => $address1,
City => $city,
Country => $country,
Privileged => 1);
}