RT3BatchAddUsers: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
m (2 revisions imported)
 
No edit summary
Line 1: Line 1:
<nowiki>#!/usr/bin/perl -w
<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=&lt;USERS_DATA&gt;;
  @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-&gt;Create(Name =&gt; $username,
  $UserObj-&gt;Create(Name => $username,
  RealName =&gt; $realname,
  RealName => $realname,
                   EmailAddress =&gt; $email_address,
                   EmailAddress => $email_address,
                   Password =&gt; 'Passw0rd',
                   Password => 'Passw0rd',
  Organization =&gt; $organization,
  Organization => $organization,
  Address1 =&gt; $address1,
  Address1 => $address1,
  City =&gt; $city,
  City => $city,
  Country =&gt; $country,
  Country => $country,
  Privileged =&gt; 1);
  Privileged => 1);
  }
  }
  </nowiki>
   
</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 &lt;mohamed.elerian@britishcouncil.org.eg,melerian@gmail.com&gt;
 # Partly based on script provided by David Maze &lt;dmaze@cag.lcs.mit.edu&gt;
 # 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-&gt;Create(Name => $username,
 		 RealName => $realname,
                  EmailAddress => $email_address,
                  Password => 'Passw0rd',
 		 Organization => $organization,
 		 Address1 => $address1,
 		 City => $city,
 		 Country => $country,
 		 Privileged => 1);
 }