[rt-users] User ID in a script?

John Arends jarends at uiuc.edu
Tue Mar 25 15:16:03 EDT 2008


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:
> 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";
>>         }
>> }
>>




More information about the rt-users mailing list