User ID in a script?

I wrote a quick perl script that outputs a bunch of information about
all the users in my RT instance. I noticed that the ID numbers are all
over the place. One of my early users was created with an ID of 22, and
then the next user has an ID of 29, and then the next one is somewhere
in the mid 80s.

Does every object RT creates get a unique ID and when a user is created
it just gets the next one?

In my perl script, I want to loop through all the users so I can print
the infor for each one. Since this was a quick hack I just went through
the numbers 1 through 1000. Is there something built in that allows me
to do this in a more direct way? I don’t want to loop until there is no
data since it seems like the ID numbes are all over the place.

#!/usr/bin/perl

use warnings;
use lib ‘/usr/lib/perl5/vendor_perl/5.8.5/RT’;
use RT::Interface::CLI;
use RT::Ticket;
use RT::User;

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

for ($count=1; $count<1000; $count++)
{
my $user = RT::User->new( $RT::SystemUser );

$user->Load( $count );

if ( $user->Name){
	print $user->RealName . " " . $user->Name . " " . $user->EmailAddress 

. " " . $user->id . " " . $user->Privileged ." \n";
}
}

Hi John,

You can use this script as a starting point to loop through all your users:

#!/usr/bin/perl -w

External libraries

use strict;

Modify the next line to fit your installation

use lib (“/opt/local/software/rt-3.6.3/lib”);
package RT;
use RT::Interface::CLI qw(CleanEnv loc);
use RT::Users;
CleanEnv();
RT::LoadConfig();
RT::Init();
my $users = new RT::Users($RT::SystemUser);
$users->order_by(VALUE => ‘Id’);

Loop through users

while ( my $User = $users->Next ) {
print sprintf(“UserID: %s, RealName: %s\n”,
$User->Id(), $User->RealName());
}

Regards,
Gene

At 01:50 PM 3/17/2008, John Arends wrote:

I wrote a quick perl script that outputs a bunch of information about
all the users in my RT instance. I noticed that the ID numbers are all
over the place. One of my early users was created with an ID of 22, and
then the next user has an ID of 29, and then the next one is somewhere
in the mid 80s.

Does every object RT creates get a unique ID and when a user is created
it just gets the next one?

In my perl script, I want to loop through all the users so I can print
the infor for each one. Since this was a quick hack I just went through
the numbers 1 through 1000. Is there something built in that allows me
to do this in a more direct way? I don’t want to loop until there is no
data since it seems like the ID numbes are all over the place.

#!/usr/bin/perl

use warnings;
use lib ‘/usr/lib/perl5/vendor_perl/5.8.5/RT’;
use RT::Interface::CLI;
use RT::Ticket;
use RT::User;

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

for ($count=1; $count<1000; $count++)
{
my $user = RT::User->new( $RT::SystemUser );

    $user->Load( $count );

    if ( $user->Name){
            print $user->RealName . " " . $user->Name . " " . 

$user->EmailAddress
. " " . $user->id . " " . $user->Privileged ." \n";
}
}


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Gene LeDuc, GSEC
Security Analyst
San Diego State University

Gene,

When running your script I get this error:

[Tue Mar 25 19:12:39 2008] [crit]: Can’t locate object method "order_by"
via package “RT::Users” at ./rtusers.pl line 14.
(/usr/lib/perl5/vendor_perl/5.8.5/RT.pm:346)
Can’t locate object method “order_by” via package “RT::Users” at
./rtusers.pl line 14.

In poking around the perdoc info for RT::Users and RT::Users_Overlay I
didn’t see any mention of order_by so I’m not how to proceed from there.

-John

Gene LeDuc wrote:

Gene,

When running your script I get this error:

[Tue Mar 25 19:12:39 2008] [crit]: Can’t locate object method
“order_by”
via package “RT::Users” at ./rtusers.pl line 14.
(/usr/lib/perl5/vendor_perl/5.8.5/RT.pm:346)
Can’t locate object method “order_by” via package “RT::Users” at
./rtusers.pl line 14.

You want the OrderBy method, which is documented in
perldoc DBIx::SearchBuilder

There are also a number of example usages if you grep through RT’s
perl modules

-kevin

Hi John,

I don’t really have an answer for this error because it works on my
installation. DBIx::SearchBuilder::order_by is included as a method in
RT::Users and many other RT classes. I found it by snooping in a text file
I stumbled across (probably on the wiki) that enumerates many of the RT
classes. I’ve attached it to this message.

Regards,
Gene

At 12:16 PM 3/25/2008, John Arends wrote:

rtclasses.zip (9.04 KB)