[rt-users] Add group membership via CLI

Asif Iqbal vadud3 at gmail.com
Tue May 14 17:20:38 EDT 2013


I followed the script from Emmanuel and Tanguy from Nov 20, 2010 with this
subject to add a list of members to a group and it is failing. I made some
changes to match page 99 of the RT Essentials book.

#!/usr/bin/perl -w
use strict;
use lib "/opt/rt3/lib";

use RT;
use RT::Interface::CLI qw( CleanEnv GetCurrentUser );

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

my $user = RT::User->new( $RT::SystemUser );
my $group = RT::Group->new( $RT::SystemUser );
my $inputgroup = $ARGV[0];

$group->LoadUserDefinedGroup( $inputgroup );

open FILE, "user_list.txt" or die $!;

while (<FILE>)
{
  $user->Load( $_ );
  $group->AddMember( $user->PrincipalObj->Id );
}

close FILE;


$ ./rtgroupmember.pl MYGROUP
[Tue May 14 20:34:50 2013] [error]: Couldn't get principal for not loaded
object (/opt/rt3/lib/RT/User_Overlay.pm:1154)
[Tue May 14 20:34:50 2013] [crit]: Can't call method "Id" on an undefined
value at ./rtgroupmember.pl line 28, <FILE> line 1. (/opt/rt3/lib/RT.pm:377)
Can't call method "Id" on an undefined value at ./rtgroupmember.pl line 28,
<FILE> line 1.

So I changed the RT::User->new with RT::User_Overlay->new and I got a
different error saying cannot use object method new.


Don't speak much OOO perl yet.


Any suggestion would be appreciated.


-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20130514/dcd057c0/attachment.htm>


More information about the rt-users mailing list