[rt-users] User ID in a script?

Gene LeDuc gleduc at mail.sdsu.edu
Mon Mar 17 18:04:06 EDT 2008


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";
>         }
>}
>
>_______________________________________________
>http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
>Community help: http://wiki.bestpractical.com
>Commercial support: sales at 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 




More information about the rt-users mailing list